View Full Version : QTcpServer: No such file or directory (Qt 4, SuSe 10)
freak
10th May 2006, 22:55
I'm trying to create a QTcpServer inside a QThread. I get the error "QTcpServer: No such file or directory" error.
The include path is not added to the Makefile when running the following:
qmake -project
qmake
Has anyone seen this problem, if so, how would you go about solving it? Thanks in advanced.
jacek
10th May 2006, 23:09
Add "QT += network" to your .pro file.
freak
10th May 2006, 23:35
Thanks a lot for the help. This fixed my problem with the missing Include and Library.
I am able to compile my code but when I run it I get the following error:
ASSERT failure in QObject::QObject(): "Cannot create children for a parent that is in a different thread."
The code is the following:
mythread::mythread()
{
tcpServ = new QTcpServer(this);
}
mythread::run()
{
while(isRunning())
{
tcpServ->listen();
}
exec();
}
One more question. Since this is a different problem/question do I continue in this thread or is it best placed as a new thread?
Thanks for the help.
jacek
11th May 2006, 00:00
ASSERT failure in QObject::QObject(): "Cannot create children for a parent that is in a different thread."
When the constructor is executed that new thread doesn't exist yet (not mentioning that mythread object lives in a thread that created it). If you create an object in the constructor it will live in a wrong thread. Therefore you should create QTcpServer in mythread::run() (without a parent):
mythread::run()
{
tcpServ = new QTcpServer();
while(isRunning())
{
tcpServ->listen();
}
exec();
}
http://doc.trolltech.com/4.1/threads.html
Since this is a different problem/question do I continue in this thread or is it best placed as a new thread?
Next time, please, start a new thread.
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.