QTimer can only be used with threads started with QThread

前端 未结 2 2022
情深已故
情深已故 2020-12-11 15:48

So I have an interesting problem....a program I am (trying) to write is crashing with this error:

QObject::startTimer: QTimer can only be used with threads s         


        
相关标签:
2条回答
  • 2020-12-11 16:08

    This may be related to creating the QNetworkAccessManager inside the Send method - try instead using RAII.

    Define the QNetworkAccessManager in the header for Transmissions as a class variable, and create a class instance it in the ctor, then you will be able to post to it from the Send thread.

    Otherwise I think it goes out of scope.

    0 讨论(0)
  • 2020-12-11 16:13

    To use a QTimer you need to have an event loop. QNAM obviously uses a timer to periodically check for the network reply.

    You need to start the application event loop with QCoreApplication::exec() and then call QNAM methods like post after that.

    I think you can call post before exec but you may come across this bug.

    Also, note that up to Qt 4.7 QNAM did not use threading but with 4.8 this is changing.

    0 讨论(0)
提交回复
热议问题