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] QLabel output freezes when outputting data from separate process
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] QLabel output freezes when outputting data from separate process

Scheduled Pinned Locked Moved General and Desktop
5 Posts 4 Posters 2.3k 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.
  • R Offline
    R Offline
    rizoritis
    wrote on last edited by
    #1

    Hello,

    I have two processes (One from Qt and one external) which I am using QSharedMemory as my IPC for. In my Qt GUI I have a separate thread that emits a signal to update my QLabel outputs every 100 ms. For some reason when I run the application my GUI's QLabel outputs randomly run then freeze, then come back, then freeze again, etc. Sometimes if I move the window around it unfreezes from a frozen state with the current value. I am thinking it might have something to do with thread priority because it seems that the GUI just gives up the processor for something else to run and doesn't update anything. Another thought I had was something with locking/unlocking the shared memory, but I am not sure how that would effect the output of the GUI freezing. I am more inclined to think it is my first assumption. I was wondering what anyone's thoughts were and if I may be wrong with what the problem is. Any feedback is greatly appreciated.

    Thanks

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

      Hi,

      Without any code, it's difficult to diagnose anything. You should at least show the QSharedMemory related code.

      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
      • R Offline
        R Offline
        rizoritis
        wrote on last edited by
        #3

        [quote author="SGaist" date="1370032085"]Hi,

        Without any code, it's difficult to diagnose anything. You should at least show the QSharedMemory related code.[/quote]

        Below is my code:

        @void BasicGui::createSharedMemory()
        {
        QString SHMEMKEY;
        int size = sizeof(double);

        if(sharedMemory.isAttached()) {sharedMemory.detach();}
        
        sharedMemory.setKey("SharedMemory");
        
        if(!sharedMemory.create(size, QSharedMemory::ReadWrite))
        {
            qDebug() << "Unable to create shared memory segment!";
            qDebug() << "Error code: " << sharedMemory.errorString();
        }
        
        qDebug() << "Shared memory was created with a size of " << sharedMemory.size();
        SHMEMKEY = sharedMemory.nativeKey();
        qDebug() << "Native shared memory key: " << SHMEMKEY;
        
        sharedMemory.attach();
        
        pSharedMemory = sharedMemory.data();
        

        }@

        So after this I use the following line in another part of code to read the data (gui_data) in the UI:

        @gui_data = (gui_mot_data_t*)pSharedMemory;@

        I have the GUI updating dats from the shared memory in another thread as follows:

        @void GuiUpdate::run()
        {
        while(1)
        {
        updateGuiSignal();
        Sleep(100);
        }
        }@

        I use a signal and slot for this:

        @QObject::connect(&guiupdate, SIGNAL(updateGuiSignal()), &basicgui, SLOT(updateGuiSlot()), Qt::DirectConnection);
        @

        So, after running my code I find that some of the UI outputs (lets say positions being continuously updated) just stop updating themselves and randomly come back to life or don't ever come back at all. What can be causing this?

        1 Reply Last reply
        0
        • TheBadgerT Offline
          TheBadgerT Offline
          TheBadger
          wrote on last edited by
          #4

          You are not supposed to update GUI objects (QLabel in your case) from another thread than the main application thread (more info on "this":http://www.qtforum.org/article/26801/qt4-threads-and-widgets.html thread).

          So the solution would be to use signals and slots but

          [quote author="rizoritis" date="1370348224"]
          I use a signal and slot for this:

          @
          QObject::connect(&guiupdate, SIGNAL(updateGuiSignal()), &basicgui, SLOT(updateGuiSlot()), Qt::DirectConnection);
          @

          [/quote]

          I think the problem is using the Qt::DirectConnection. Any reason why it should be direct, refer to the documentation about the "Qt::ConnectionType":http://qt-project.org/doc/qt-4.8/qt.html#ConnectionType-enum options, my guess is that Qt::AutoConnection is the better option.


          Check out my SpellChecker Plugin for Qt Creator @ https://github.com/CJCombrink/SpellChecker-Plugin

          1 Reply Last reply
          0
          • K Offline
            K Offline
            KA51O
            wrote on last edited by
            #5

            signal slot connections between different threads should always be QueuedConnections (although AutoConnection should work as well since it detects the correct type).

            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