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. Communication problems between MainWindow and QThread

Communication problems between MainWindow and QThread

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 751 Views 3 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.
  • alexRHTA Offline
    alexRHTA Offline
    alexRHT
    wrote on last edited by alexRHT
    #1

    Hi everybody,

    I am having the following problem:

    In MainWindow class I have defined this signal:

    signals:
    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!

    kshegunovK 1 Reply Last reply
    0
    • alexRHTA alexRHT

      Hi everybody,

      I am having the following problem:

      In MainWindow class I have defined this signal:

      signals:
      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!

      kshegunovK Offline
      kshegunovK Offline
      kshegunov
      Moderators
      wrote on last edited by
      #2

      Hi,
      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.

      Read and abide by the Qt Code of Conduct

      1 Reply Last reply
      2
      • alexRHTA Offline
        alexRHTA Offline
        alexRHT
        wrote on last edited by
        #3

        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!

        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