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. [Solved] Qt event with blocking queue implemented with boost
Forum Updated to NodeBB v4.3 + New Features

[Solved] Qt event with blocking queue implemented with boost

Scheduled Pinned Locked Moved General and Desktop
7 Posts 2 Posters 2.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.
  • B Offline
    B Offline
    bence.takacs
    wrote on last edited by
    #1

    I have to use a blocking queue implemented with boost and emit a SIGNAL when the runner thread wakes up.
    What is the simplest way doing this? I'm interested in both fixes of my solution or different working solutions too.

    My solution is not working: shows the legendary "undefined reference to vtable" error.

    mediator.cpp:
    @Mediator::Mediator(QObject *parent) : QObject(parent) {
    ...
    boost::thread myThread (callbackThread, this, &blocking_queue);
    }

    static void callbackThread(Mediator* mediator, multi_consumer_mutexed_struct<item>* blocking_queue){
    item it;;
    for(;;){
    try{
    blocking_queue->wait_and_read(&it);
    cout << "Item arrived" <<endl;
    mediator->imageRefreshed();
    } catch(const boost::thread_interrupted&){
    break;
    }
    }
    }

    void Mediator::imageRefreshed(){
    emit imageRefreshedSignal();
    }@

    mediator.h:
    @class Mediator : public QObject
    {
    Q_OBJECT

    public:
    Mediator(QObject *parent);
    ~Mediator();

    void imageRefreshed();
    

    signals:
    void imageRefreshedSignal();

    };

    static void callbackThread(Mediator* mediator, multi_consumer_mutexed_struct<item>* blocking_queue);@

    Without extending QObject and puts into callbackThread then everything is fine: the thread awakes when a new item arrived to the queue and read it out. But if I want to emit a signal I need to use the Q_OBJECT macro and extend QObject, and then the issues starts. Don't ask about the multi_consumer_mutexed_struct itself: it works as a blocking queue and I just need to use that but it is not my product :-)

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Did you re-run qmake after add/removing Q_OBJECT ? Generally a vtable error occurs when moc wasn't run properly

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • B Offline
        B Offline
        bence.takacs
        wrote on last edited by
        #3

        I'm using Qt Creator and using 'Build Project' and 'Run Project' buttons.
        Is that enough? If not what should I do? I haven't run qmake from console so far.

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          You can call "run qmake" from the build menu and you should be fine

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • B Offline
            B Offline
            bence.takacs
            wrote on last edited by
            #5

            Hmmm... I've just run 'qmake' from the command line and it said that it does not find some source files. I fixed the path and pressed "Run Project" and now everything is fine.

            The question is: how could this happen... a project with wrong source paths and no errors upon building.. maybe it did incremental build those were built already...

            Anyway: now it's working and thanks for the help.

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              It depends on where you ran qmake. Did you run it in the shadow build ?

              You're welcome !

              Since you have it working now, please update the thread title prepending [solved] so other forum users may know a solution has been found :)

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0
              • B Offline
                B Offline
                bence.takacs
                wrote on last edited by
                #7

                Connected topicshttp://cidebycide.blogspot.hu/2012/08/updating-qt-gui-from-boostthread.html
                http://qt-project.org/doc/qt-4.8/threads-qobject.html
                https://qt-project.org/forums/viewthread/10459

                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