QTcpServer - program finishes after listen
I'm new with Qt so please excuse me for a simple question.
I need to create a simple tcp client-server application. I found a "youtube video":http://www.youtube.com/watch?v=BSdKkZNEKlQ explaining how to use QTcpServer. Problem is that my program finishes before client doesnt manage to connect.
What is the problem? I'm not well with streams and threads, does listen() method start a new thread?
Thank you for your answers
[code]QT += core network
QT -= gui
TARGET = server
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
SOURCES += main.cpp
class MyServer : public QObject
explicit MyServer(QObject *parent = 0);
#endif // MYSERVER_H
MyServer::MyServer(QObject *parent) :
server = new QTcpServer(this);
connect(server, SIGNAL(newConnection()), this, SLOT(acceptConnection()));
printf("Server could not start\r\n");
QTcpSocket *socket = server->nextPendingConnection();
int main(int argc, char * argv)
QCoreApplication a(argc, argv);
printf( "finished" );
[code]open 127.0.0.1 1234[/code]
Problem suddenly was solved. I did nothing ^_^
code_fodder last edited by
I would just note that I have found sometimes when developing I can get some build errors, then undo my changes and still have errors. Then when I delete all my objects / output files and do a full re-build the problem goes away.
Sometimes I think the build process gets the files it needs to re-compile or not confused and this can cause strange issues...
That's just a note, its not a concrete issue, just something I have observed.
Jeroentjehome last edited by
When in doubt it is always a good thing to remove all object files and recompile. That's standard compilation mixup fix.