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. Qt show() in boost coroutine function
Forum Updated to NodeBB v4.3 + New Features

Qt show() in boost coroutine function

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 3 Posters 353 Views
  • 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.
  • I Offline
    I Offline
    iamfly
    wrote on 22 Feb 2024, 06:19 last edited by
    #1

    I was trying to show a widget in boost coroutine, and called show() crashed.
    Boost version is 1.83.0, Qt version is 5.15.2

    Here is my code:

    QFile uiFile = QFile(QString("a.ui"));
    if (!uiFile.open(QIODevice::ReadOnly))
    {
    	return;
    }
    QUiLoader loader;
    
    QWidget* pWidget = loader.load(&uiFile);
    pWidget->show();
    uiFile.close();
    

    Here is call stack:
    ab936ce3-23c6-4ea4-ac4f-cab971d32b57-image.png

    613675ce-be24-45d5-97a7-edfe2446c1e4-image.png

    C 1 Reply Last reply 22 Feb 2024, 06:20
    0
    • I iamfly
      22 Feb 2024, 06:19

      I was trying to show a widget in boost coroutine, and called show() crashed.
      Boost version is 1.83.0, Qt version is 5.15.2

      Here is my code:

      QFile uiFile = QFile(QString("a.ui"));
      if (!uiFile.open(QIODevice::ReadOnly))
      {
      	return;
      }
      QUiLoader loader;
      
      QWidget* pWidget = loader.load(&uiFile);
      pWidget->show();
      uiFile.close();
      

      Here is call stack:
      ab936ce3-23c6-4ea4-ac4f-cab971d32b57-image.png

      613675ce-be24-45d5-97a7-edfe2446c1e4-image.png

      C Offline
      C Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on 22 Feb 2024, 06:20 last edited by Christian Ehrlicher
      #2

      @iamfly You must not access gui elements from outside the main thread.

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      2
      • I Offline
        I Offline
        iamfly
        wrote on 22 Feb 2024, 07:15 last edited by
        #3

        @Christian-Ehrlicher

        You mean no possible to access qt widgets outside mainthread? Or how about use qt coroutine?

        J 1 Reply Last reply 22 Feb 2024, 07:22
        0
        • I iamfly
          22 Feb 2024, 07:15

          @Christian-Ehrlicher

          You mean no possible to access qt widgets outside mainthread? Or how about use qt coroutine?

          J Offline
          J Offline
          jsulm
          Lifetime Qt Champion
          wrote on 22 Feb 2024, 07:22 last edited by
          #4

          @iamfly said in Qt show() in boost coroutine function:

          You mean no possible to access qt widgets outside mainthread?

          Yes. Do not modify UI outside of the main thread. Other threads can emit signals to trigger changes in the UI and pass data to it. In main thread you subscribe to these signals and modify the UI.

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          I 1 Reply Last reply 22 Feb 2024, 07:45
          1
          • J jsulm
            22 Feb 2024, 07:22

            @iamfly said in Qt show() in boost coroutine function:

            You mean no possible to access qt widgets outside mainthread?

            Yes. Do not modify UI outside of the main thread. Other threads can emit signals to trigger changes in the UI and pass data to it. In main thread you subscribe to these signals and modify the UI.

            I Offline
            I Offline
            iamfly
            wrote on 22 Feb 2024, 07:45 last edited by
            #5

            @jsulm Thanks, i will try that way.

            1 Reply Last reply
            0

            1/5

            22 Feb 2024, 06:19

            • Login

            • Login or register to search.
            1 out of 5
            • First post
              1/5
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved