Two windows in the same main
Hi!
Sorry if this is a dumb question but I have no past experience with threads and/or network communication.
I'm making a simple tcp communication: I have a sender and I have a receiver.
For now I have 2 different project in QtCreator, one for the sender and one for the receiver. I'm testing the network communication in this way: I open the receiver and then and I open the sender.
But I'd like to have a single progect called SenderReceiverTest that open 2 window, one for the receiver, one for the sender, in the same QtCreator project.
First question: Is this single-project stuff a good idea?
Then...
If i have something like this:
Code:
#include <QtGui/QApplication>
#include "windowsender.h"
#include "windowreceiver.h"
int main(int argc, char *argv[])
{
WindowReceiver r;
r.show();
WindowSender s;
s.show();
QObject::connect(&r,
SIGNAL(windowClosed
()),
// custom virtual void closeEvent(QCloseEvent *e) &s, SLOT(close()));
QObject::connect(&s,
SIGNAL(windowClosed
()),
// custom virtual void closeEvent(QCloseEvent *e) &r, SLOT(close()));
return a.exec();
}
Second question:
The two window are in the same thread, aren't they? I'd like to have the two windows in different thread for testing real async communication.. and for that I should have two dirrefent thread.. right? How can I do this?
Re: Two windows in the same main
You can't. Qt GUI objects can exist only in main thread.
Re: Two windows in the same main
For testing asynchronous communication you don't need threads.
Re: Two windows in the same main
thank you for the answer.
so the way i'm handling it now (two window.show in the same main) is a right way?
is there a better way?
Re: Two windows in the same main
It's ok but don't create two instances of QApplication. One is enough. Your current code would not even compile :)
Re: Two windows in the same main
Ah yeah sorry I have done some cut and paste for deleting comments and renaming the objects and there was a mistake.. : )
So it is ok, I can test how many TCP package can be sent for a second and stuffs like this, good, thank you!
One more question:
what happens if I use moveToThread methods on a QWidget subclass?
Re: Two windows in the same main
Most likely - BOOM!
Less likely, a warning and a no-op.
Re: Two windows in the same main
:)
sorry?
boom could mean runtime crash but.. no-op?
anyway thank you for the answer i have understand i don't have to do it.
Re: Two windows in the same main
Yes, boom refers to crashing :)
no-op is short for "no operation", a term using in computer science to say that an instruction will actually not do anything.
Like an empty method
Cheers,
_