In your original post, you show a run() method for your thread that does not contain a message loop and will exit almost immediately after your thread is started. The default QThread::run() runs a message loop. If you write your thread to persist and continue to run, you should execute the base class QThread::run() in your subclassed run() method or just simply call exec() in your run() method.
Without this, your thread will start and end almost instantaneously, which I'm sure is not what you intended.
Last edited by jefftee; 25th March 2016 at 22:17.
I write the best type of code possible, code that I want to write, not code that someone tells me to write!
Please pardon my late reply for I have not been at the desk during the holidays.
It's a wireless network where there is only 1 host & 1 client. The client is not able to connect if the host hasn't reached the line listen()
That's why I stick to the tutorial made directly by Qt, how does one learn the very lowest instance of a teaching unit if even this ain't running.
This might be true. However I don't even get to the point where this thread is created - which is my actual problem mentioned in the top post. As stated incomingConnection(), where this thread first is created, is never fired.
Last edited by QtExchange; 30th March 2016 at 08:38.
I did not mean another host, I meant another program.
If you have more than one interface, say actual network and loopback and another program is listening on the same port on loopback, your program will still be able to listen on the wifi network interface, but the client might connect to the server listening on loopback.
Cheers,
_
Well it is only working after listen(). In general I don't consider this as a problem, since I switched from windows libraries to Qt for networking and kept the settings (ports & addresses). With these libraries everything worked like charm, but now I switched to Qt for ensuring mulitple platform compatibility.
Why don't you post your entire project so we can see the code in its entirety or alternatively a compilable example that demonstrates the problem?
I write the best type of code possible, code that I want to write, not code that someone tells me to write!
It is working now and the reason is the listen() was in the wrong position and you need an additional Signal/Slot connection from main program to the network extension as following:
the main program gets changed like this:
Qt Code:
wifi= new WirelessNet(0); wifi->moveToThread(thread); connect(thread,SIGNAL(started()), wifi,SLOT(initWifi())); thread->start();To copy to clipboard, switch view to plain text mode
the constructor of WirelessNet is now empty, therefore it gets a new public slot function:
Qt Code:
void WirelessNet::initWifi() { }To copy to clipboard, switch view to plain text mode
And that's the trick.
If one is creating a WirelessNet-Instance, starts listenting inside the constructor but first then uses the movetoThread(), the connection is lost.
Concluding in one sentence: First move to the right thread and afterwards start listening
Thanks for your help. Let me tell you I hate the official Qt-""Tutorials""
Ah, good to know.
Well, the example you based on is actually good, it doesn't do anything weird like moving the server into another thread.
Its goal is to demonstrate how to handle client connections in separate threads and I think it does that quite well.
Cheers,
_
Bookmarks