Qt World Summit: Submit your Presentation

Communication problems between MainWindow and QThread

  • Hi everybody,

    I am having the following problem:

    In MainWindow class I have defined this signal:

    void preview(QDir* dirResults, int currIndx, SampleSlot* samSlot);

    I have in another thread a controller with this slot:

    public slots:
    void preview(QDir* dir, int ci, SampleSlot* ss);

    The connection that mainwindow.cpp contains is:

    connect(this, SIGNAL(preview(QDir*,int,SampleSlot*)), controller, SLOT(preview(QDir*,int,SampleSlot*)));

    I declare in mainwindow.cpp:

    SampleSlot *ss = new SampleSlot[20]();

    and I initialize the internal attributes of the 20 different slots of ss in base of the values obtained from the UI elements (edits, comboboxes, etc.).
    The thing is that everything seems correct in the side of the mainwindow but when I emit the following signal:

    emit preview(resultsDir, indx, ss);

    the slot receiving ss on the controller side is receiving the resultsDir and the indx correctly but not the ss. When I access ss[indx].sampleType (for example), the value does not correspond to the value it had on the mainwindow side, before emitting the signal.
    Can anybody bring some light to this issue?
    Thanks in advance!

  • Moderators

    Before anything else you should fix the race conditions. You can't pass things through their addresses (i.e. with pointers) across threads without serializing access to those objects. As for your second problem, my guess is the object the pointer's referencing goes out of scope, but this you should debug.

    Kind regards.

  • Thank you very much for your words.
    Assuming I was going out of scope I changed my definition of the ss according to https://www.gidforums.com/t-12539.html
    Problem solved!

Log in to reply