Event notifiers cannot be disabled from another thread



  • Sorry I'm not experianced enough to understand the error I'm getting.
    I Followed the example provided at "http://qt-project.org/wiki/QThreads_general_usage".
    And wrote code that looks almost identical.

    In my main program I have:
    @MotorClass *MotorObj = new MotorClass;
    QThread *MotorThread = new QThread;

    MotorObj->moveToThread(MotorThread);

    connect(MotorThread, SIGNAL(started()), MotorObj, SLOT(run()));
    connect(MotorObj, SIGNAL(finished()), MotorThread, SLOT(quit()));
    connect(MotorObj, SIGNAL(finished()), MotorObj, SLOT(deleteLater()));
    connect(MotorThread, SIGNAL(finished()), MotorThread, SLOT(deleteLater()));

    MotorThread->start();@

    In my MotorClass Header I have:
    @class MotorClass : public QObject
    {
    Q_OBJECT
    public:
    explicit MotorClass(QObject *parent = 0);
    ~MotorClass();

    public slots:
    void run();

    signals:
    void finished();

    };@

    In my MotorClass.cpp I have:
    @MotorClass::MotorClass(QObject *parent) : QObject(parent)
    {
    }

    MotorClass::~MotorClass()
    {
    }

    void MotorClass::run()
    {
    qDebug("run");
    emit finished();
    }@

    qDebug does display the "run" message, but then it is followed by the following output and the program crashes.

    @QWinEventNotifier: event notifiers cannot be disabled from another thread
    QWinEventNotifier: event notifiers cannot be disabled from another thread
    QWinEventNotifier: event notifiers cannot be disabled from another thread
    The program has unexpectedly finished.@

    Any Ideas where I'm going wrong???


  • Moderators

    What happens in your code after you start the thread? Do you wait for it to finish or exit main immediately?



  • During execution of the thread the only thing happening at the moment is the qDebug message being printed.
    When this is done, the Thread and MotorObj is suppose to be deleted.
    The Main window remains active for user input at all times until user manually exits the main program.



  • bq. Any Ideas where I’m going wrong???

    Please read about parents in Qt. This problem one million times was already considered. Use search, be not lazy, please.



  • Kuzullis. If I Google the error I'm receiving. It is quite interesting to notice that this thread is one of the first ones popping up in the results. All the other results I have read through don't really give a clear answer. So clearly it is not so much talked about. If you feel I'm wasting your time, please don't reply to the thread. Hopefully someone else will find the thread useful.

    Is there anybody else with a bit of patience that can spot what I'm doing different from the example code given at.
    "QT Thread General Usage":http://qt-project.org/wiki/QThreads_general_usage.



  • Here is another example. But I can still not spot the difference in code. "Another Example":http://mayaposch.wordpress.com/2011/11/01/how-to-really-truly-use-qthreads-the-full-explanation/



  • Ok. I eventually followed a different route by inheriting QThread and re-implementing the run() function. I Still don't know why the above mentioned code did not work. If anyone has an idea please let me know.



  • So after about 3 Months of battling to get this thing going. I finally figured it out. MotorClass contains a QSerialPort Object. I’m not an expert on this, and just quoting what I have read. QSerialPort already provides you non-blocking mechanism for your GUI application. When running QSerialPort in another thread this somehow interferes with the way objects communicate between one another and that is where the errors are coming from. If anyone has some extra opinions on this or knows how to move a QSerialPort object into a separate thread, please do share.



  • So after about 3 Months of battling to get this thing going. I finally figured it out. MotorClass contains a QSerialPort Object. I’m not an expert on this, and just quoting what I have read. QSerialPort already provides you non-blocking mechanism for your GUI application. When running QSerialPort in another thread this somehow interferes with the way objects communicate between one another and that is where the errors are coming from. If anyone has some extra opinions on this or knows how to move a QSerialPort object into a separate thread, please do share.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.