QProgressDialog doubt
-
No, you must start gui elements in the main thread.
It depends on you application what to do exactly. If the app should block until the connection is done you can try something like this:
@
QProgressDialog pd;
// setup the dialog like postedQEventLoop el;
connect(&_tcpScoket, SIGNAL(connected()), &el, SLOT(quit()));QTcpSocket sock;
connect(&_tcpScoket, SIGNAL(connected()), &pd, SLOT(cancel()));
_tcpScoket.connectToHost("host", 80);
el.run();
pd.cancel();
@This runs a local event loop, it keeps the QApplication running, but blocks the flow of control in the method until the socket is connected (and thus the event loop stops).
You will have to add some error handling (eg. connect to the error signal of the socket) and/or add a QTimer to setup a timeout.
-
Mh, i tried to connect to a not given IP. I want to see the dialog while
@
_tcpScoket.waitForConnected(30000)
@
is active till it times out. At 30000 ms.In not working code:
@
dlg.show()
_tcpScoket.waitForConnected(30000)
dlg.cancel()
@But in this 30000ms i don't get updates to my gui. Like i expected. But i'm looking for a way, to have my progressdialog running during this 30000 ms without calling waitForConnected from another thread because i don't want to move my socket from the main thread.
I think it's not possible?