[Qt-interest] Creating QTimer from QThread
Anatoly Burakov
burakov.anatoly at gmail.com
Thu Oct 13 16:08:33 CEST 2011
Hi all
I am trying to implement the following.
I have a Server class, that spawns ServerThreads on each incoming TCP
connection. ServerThread has a signal. That signal is connected to
Server's slot. The slot creates a QTimer connects its timeout() signal
to one of other Server's signals. The problem is that despite me
calling QTimer::start(), it in fact doesn't start. This is the code
illustrating the issue:
class Server : public QMainWindow
{
void onNewConnection(int&)
{
ServerThread * thread = new ServerThread();
connect(thread, SIGNAL(someSignal()), this, SLOT(someSlot()));
// the signal is emitted from within the thread
thread->start();
}
private slots:
void someSlot()
{
QTimer * t = new QTimer();
t.setSingleShot(true);
connect(t, SIGNAL(timeout()), this, SLOT(anotherSlot()));
t.start(1000);
}
void otherSlot()
{
// do something
}
}
I can detect that someSlot() is being called, so the problem is QTimer
not starting or its events not being processed (probably because i did
something fundamentally wrong due to my more than appalling knowledge
of multithreaded programming). What can i do?
--
Best regards,
Anatoly
More information about the Qt-interest-old
mailing list