Qt World Summit: Register Today!

[Solved] Qt event with blocking queue implemented with boost

  • 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::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;;
    cout << "Item arrived" <<endl;
    } catch(const boost::thread_interrupted&){

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

    @class Mediator : public QObject

    Mediator(QObject *parent);

    void imageRefreshed();

    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 :-)

  • Lifetime Qt Champion


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

  • 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.

  • Lifetime Qt Champion

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

  • 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.

  • Lifetime Qt Champion

    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 :)

  • Connected topicshttp://cidebycide.blogspot.hu/2012/08/updating-qt-gui-from-boostthread.html

Log in to reply