Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Event notifiers cannot be disabled from another thread
Forum Updated to NodeBB v4.3 + New Features

Event notifiers cannot be disabled from another thread

Scheduled Pinned Locked Moved General and Desktop
9 Posts 3 Posters 4.8k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    achmed
    wrote on last edited by
    #1

    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???

    1 Reply Last reply
    0
    • Chris KawaC Offline
      Chris KawaC Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on last edited by
      #2

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

      1 Reply Last reply
      0
      • A Offline
        A Offline
        achmed
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        0
        • K Offline
          K Offline
          kuzulis
          Qt Champions 2020
          wrote on last edited by
          #4

          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.

          1 Reply Last reply
          0
          • A Offline
            A Offline
            achmed
            wrote on last edited by
            #5

            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.

            1 Reply Last reply
            0
            • A Offline
              A Offline
              achmed
              wrote on last edited by
              #6

              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/

              1 Reply Last reply
              0
              • A Offline
                A Offline
                achmed
                wrote on last edited by
                #7

                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.

                1 Reply Last reply
                0
                • A Offline
                  A Offline
                  achmed
                  wrote on last edited by
                  #8

                  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.

                  1 Reply Last reply
                  0
                  • A Offline
                    A Offline
                    achmed
                    wrote on last edited by
                    #9

                    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.

                    1 Reply Last reply
                    0

                    • Login

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • Users
                    • Groups
                    • Search
                    • Get Qt Extensions
                    • Unsolved