Why Qt hangs?
-
When I create a thread with
@HANDLE thread = CreateThread(0, 0, (LPTHREAD_START_ROUTINE)MainWindow::newConntact(), NULL, 0, 0);@
the program hangs on ClientSocket = accept(ListenSocket, NULL, NULL); in the thread.I thought that this is done in parallel. -
Sorry,
how is this question related to Qt??
-
Well this happens only in qt.I mean when I push the button for the socket the program hangs.
-
[quote author="dwsld" date="1363979507"]Well this happens only in qt.I mean when I push the button for the socket the program hangs.[/quote]
I think the codes are NOT Qt-specific (I think they are M$'s API). Why not use QThread instead? It might be a problem with MOC.
-
Could you please define 'hangs'?
As I read it, you GUI freezes because the program is waiting on the accept call to return.
-
[quote author="NL - Danny" date="1363988269"]Could you please define 'hangs'?
you GUI freezes because the program is waiting on the accept call to return.[/quote]
Yes
-
Check the documentation about QThread: "Click":http://qt-project.org/doc/qt-4.8/qthread.html
Goodluck! -
I have some error :
mainwindow.obj:-1: error: LNK2001: unresolved external symbol "public: virtual struct QMetaObject const * __thiscall Worker::metaObject(void)const " (?metaObject@Worker@@UBEPBUQMetaObject@@XZ).mainwindow.obj:-1: error: LNK2001: unresolved external symbol "public: virtual void * __thiscall Worker::qt_metacast(char const *)" (?qt_metacast@Worker@@UAEPAXPBD@Z)
mainwindow.obj:-1: error: LNK2001: unresolved external symbol "public: virtual int __thiscall Worker::qt_metacall(enum QMetaObject::Call,int,void * *)" (?qt_metacall@Worker@@UAEHW4Call@QMetaObject@@HPAPAX@Z)
@
class Worker : public QObject
{
Q_OBJECTpublic slots:
void doWork() {
/* ... */
}
};.....
QThread *thread = new QThread;
Worker *worker = new Worker;
worker->moveToThread(thread);
thread->start();@ -
Few things you could try / check:
- clean and rebuild
- Check in the implementation file if the classname is in front of the methods (Worker::doWork() etc)
- moc the class (run QMake)
-
If you were actually using the Qt networking classes there'd be no blocking by default and you almost certainly would not need the additional complexity of a thread.
-
HI,
how I said in my first post, if you use non Qt classes for Networking the problem can be related only to Qt.
How ChrisW67 wrote, Qt Networkin classes isn't blockingPlease post code related to Networking