[Qt-interest] Creating QTimer from QThread

Constantin Makshin cmakshin at gmail.com
Fri Oct 14 08:20:36 CEST 2011


Also make sure you connect the signal to an existing slot (anotherSlot() vs.
otherSlot()). ;)
On Oct 13, 2011 6:11 PM, "Anatoly Burakov" <burakov.anatoly at gmail.com>
wrote:

> 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
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at qt.nokia.com
> http://lists.qt.nokia.com/mailman/listinfo/qt-interest
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20111014/482c2ac8/attachment.html 


More information about the Qt-interest-old mailing list