Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
pmanager
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Zenghong Chen
pmanager
Commits
3f9deb29
Commit
3f9deb29
authored
7 years ago
by
Zenghong Chen
Browse files
Options
Downloads
Patches
Plain Diff
mainwindow.cpp
parent
d9dead67
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
mainwindow.cpp
+240
-0
240 additions, 0 deletions
mainwindow.cpp
with
240 additions
and
0 deletions
mainwindow.cpp
0 → 100644
+
240
−
0
View file @
3f9deb29
#include
"mainwindow.h"
#include
"ui_mainwindow.h"
static
QTcpSocket
*
socket
;
int
ifconnected
=
0
;
QString
labelbuff
;
QVector
<
QString
>
textbuffer
(
10000
);
int
textbuffer_index
=
0
;
bool
if_loadfile
=
false
;
int
textbuffer_size
=
0
;
QFont
font1
;
QFont
font2
;
QPalette
palette1
;
QPalette
palette2
;
MainWindow
::
MainWindow
(
QWidget
*
parent
)
:
QMainWindow
(
parent
),
ui
(
new
Ui
::
MainWindow
)
{
ui
->
setupUi
(
this
);
//ui->lineEdit->setText("127.0.0.1");
ui
->
lineEdit
->
setText
(
"192.168.0.103"
);
ui
->
lineEdit_2
->
setText
(
"1234"
);
ui
->
lineEdit_3
->
setText
(
"Hello Gateway!"
);
socket
=
new
QTcpSocket
(
this
);
connect
(
socket
,
SIGNAL
(
connected
()),
this
,
SLOT
(
connected
()));
connect
(
socket
,
SIGNAL
(
disconnected
()),
this
,
SLOT
(
disconnected
()));
connect
(
socket
,
SIGNAL
(
readyRead
()),
this
,
SLOT
(
readyRead
()));
connect
(
socket
,
SIGNAL
(
bytesWritten
(
qint64
)),
this
,
SLOT
(
bytesWritten
(
qint64
)));
font1
.
setPixelSize
(
50
);
//font2.setPixelSize(11);
font2
=
ui
->
textBrowser
->
font
();
//font2.setFamily(font.defaultFamily());
palette1
.
setColor
(
QPalette
::
WindowText
,
Qt
::
red
);
palette2
.
setColor
(
QPalette
::
WindowText
,
Qt
::
black
);
}
MainWindow
::~
MainWindow
()
{
delete
ui
;
}
void
MainWindow
::
on_pushButton_clicked
()
// Connect/Disconnect-Button
{
if
(
ifconnected
)
//connected, then break the connection
{
ifconnected
=
0
;
socket
->
disconnectFromHost
();
}
else
//not conneted, then connect to host
{
ifconnected
=
1
;
socket
->
connectToHost
(
ui
->
lineEdit
->
text
(),
ui
->
lineEdit_2
->
text
().
toInt
());
}
}
void
MainWindow
::
on_pushButton_2_clicked
()
// Send-Button
{
if
(
socket
->
state
()
==
QAbstractSocket
::
ConnectedState
)
{
if
(
if_loadfile
)
{
//backup: socket->write(ui->lineEdit_3->text().toUtf8());
if
(
ui
->
checkBox
->
checkState
()
==
Qt
::
Checked
){
//socket->write(ui->lineEdit_3->te
//ui->textBrowser->li
socket
->
write
(
ui
->
lineEdit_3
->
text
().
toUtf8
());
//send the current content in the box and show the next line
if
(
ui
->
lineEdit_3
->
text
()
!=
textbuffer
[
textbuffer_index
])
return
;
if
(
textbuffer_index
<
textbuffer_size
-
1
)
{
textbuffer_index
++
;
qDebug
()
<<
textbuffer_size
;
}
refresh_codepad
();
ui
->
lineEdit_3
->
setText
(
textbuffer
[
textbuffer_index
]);
}
else
{
for
(
int
i
=
textbuffer_index
;
i
<
textbuffer_size
;
i
++
)
{
socket
->
write
(
textbuffer
[
i
].
toUtf8
());
}
textbuffer_index
=
textbuffer_size
-
1
;
refresh_codepad
();
ui
->
lineEdit_3
->
setText
(
textbuffer
[
textbuffer_index
]);
}
}
else
socket
->
write
(
ui
->
lineEdit_3
->
text
().
toUtf8
());
}
else
{
ui
->
textBrowser
->
append
(
"Unconnected to server, please connect..."
);
}
}
void
MainWindow
::
connected
()
{
qDebug
()
<<
"Connected!"
;
ui
->
pushButton
->
setText
(
"disconnect"
);
ui
->
textBrowser
->
append
(
"Connected"
);
}
void
MainWindow
::
disconnected
()
{
qDebug
()
<<
"Disconnected!"
;
ui
->
pushButton
->
setText
(
"connect"
);
ui
->
textBrowser
->
append
(
"Disconnected"
);
}
void
MainWindow
::
bytesWritten
(
qint64
bytes
)
{
qDebug
()
<<
"we wrote: "
<<
bytes
;
labelbuff
=
"we wrote: "
;
labelbuff
.
append
(
QString
::
number
(
bytes
));
labelbuff
.
append
(
" bytes"
);
ui
->
textBrowser
->
append
(
labelbuff
);
}
void
MainWindow
::
readyRead
()
{
qDebug
()
<<
"Reading..."
;
//qDebug() << socket->readAll();
ui
->
textBrowser
->
append
(
"Reading..."
);
ui
->
textBrowser
->
append
(
QString
::
fromUtf8
(
socket
->
readAll
()));
}
void
MainWindow
::
on_pushButton_3_clicked
()
{
this
->
close
();
}
void
MainWindow
::
on_pushButton_4_clicked
()
{
QString
filename
=
QFileDialog
::
getOpenFileName
(
this
,
"Open THE File"
,
""
,
"(*.*)"
);
QFile
file
(
filename
);
if
(
file
.
open
(
QFile
::
ReadOnly
))
{
//ui->lineEdit_3->setText(file.readAll());
/*if(ui->checkBox->checkState()== Qt::Unchecked){
}
else{
char buf[][12];
while(1)
{
qint64 lineLength = file.readLine(buf, sizeof(buf));
if (lineLength != -1) {
//ui->label_3->
ui->textBrowser->append(buf);
}
else
{
break;
}
}
//}
*/
if_loadfile
=
true
;
int
i
=
0
;
textbuffer_index
=
0
;
char
buf
[
1024
];
while
(
1
)
{
qint64
lineLength
=
file
.
readLine
(
buf
,
sizeof
(
buf
));
if
(
lineLength
!=
-
1
)
{
textbuffer
[
i
]
=
QString
::
fromStdString
(
buf
);
i
++
;
}
else
{
break
;
}
}
textbuffer_size
=
i
;
refresh_codepad
();
ui
->
lineEdit_3
->
setText
(
textbuffer
[
0
]);
}
}
void
MainWindow
::
on_checkBox_clicked
()
{
}
void
MainWindow
::
on_pushButton_5_clicked
()
//last line
{
if
(
if_loadfile
)
{
if
(
textbuffer_index
>
0
)
{
textbuffer_index
--
;
}
ui
->
lineEdit_3
->
setText
(
textbuffer
[
textbuffer_index
]);
}
qDebug
()
<<
textbuffer_index
;
refresh_codepad
();
}
void
MainWindow
::
on_pushButton_6_clicked
()
//next line
{
if
(
if_loadfile
)
{
if
(
textbuffer_index
<
textbuffer_size
-
1
)
{
textbuffer_index
++
;
}
ui
->
lineEdit_3
->
setText
(
textbuffer
[
textbuffer_index
]);
}
qDebug
()
<<
textbuffer_index
;
refresh_codepad
();
}
void
MainWindow
::
refresh_codepad
()
{
ui
->
textBrowser_2
->
setCurrentFont
(
QFont
(
"Timers"
,
14
,
QFont
::
Normal
));
ui
->
textBrowser_2
->
clear
();
for
(
int
i
=
0
;
i
<
textbuffer_size
;
i
++
)
{
if
(
i
==
textbuffer_index
)
{
ui
->
textBrowser_2
->
setCurrentFont
(
QFont
(
"Timers"
,
14
,
QFont
::
Bold
));
ui
->
textBrowser_2
->
setPalette
(
palette1
);
ui
->
textBrowser_2
->
append
(
textbuffer
[
i
]);
ui
->
textBrowser_2
->
setCurrentFont
(
QFont
(
"Timers"
,
14
,
QFont
::
Normal
));
ui
->
textBrowser_2
->
setPalette
(
palette2
);
}
else
ui
->
textBrowser_2
->
append
(
textbuffer
[
i
]);
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment