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. New Thread to add new tab when menu item is clicked

New Thread to add new tab when menu item is clicked

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 4 Posters 1.3k 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.
  • V Offline
    V Offline
    vsukhwal
    wrote on 23 Jan 2017, 23:03 last edited by
    #1

    Hello there,

    I want to use threads to create tabs in my qt application. Currently, I have a main menu, in which when an item is clicked a new tab is added.
    The code I am using to create a tab is as follows:
    void Home::on_actionItem_triggered()
    {
    ui->tabWidget->addTab(new tabScreen(), "tabtitle");
    }

    Can I use QFuture<void> future = QtConcurrent::run(&pool, aFunction) for the above addTab function or there might be any other way of creating a thread for the same?

    Thanks,
    Vidushi

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mrjj
      Lifetime Qt Champion
      wrote on 23 Jan 2017, 23:08 last edited by mrjj
      #2

      Hi
      All widgets must live in the main thread. So you cannot run a tab in QtConcurrent.
      You would normally run a calculation in another thread and "report back" to the widgets/GUI via signals.

      Perhaps you can describe what you are trying to build?
      Its unclear to me how adding tabs from threads could benefit an application so what is the effect
      you hope to obtain from this? :)

      1 Reply Last reply
      3
      • V Offline
        V Offline
        vsukhwal
        wrote on 24 Jan 2017, 02:58 last edited by
        #3

        The problem is that I have a grid in a tab that is taking time to create. As a result, when a user opens that tab containing the grid, the entire screen freezes and the user is incapable of performing operations on other tabs in the meantime. We would like to give users the benefit of working on the other tabs while the grid is being is loaded in a separate tab.

        In my above mentioned code, tabScreen is the grid class with its own tabscreen.h and tabscreen.cpp files which is independent from other code.

        Can you please help me achieve this functionailty?

        Thanks
        Vidushi

        J 1 Reply Last reply 24 Jan 2017, 05:16
        0
        • V vsukhwal
          24 Jan 2017, 02:58

          The problem is that I have a grid in a tab that is taking time to create. As a result, when a user opens that tab containing the grid, the entire screen freezes and the user is incapable of performing operations on other tabs in the meantime. We would like to give users the benefit of working on the other tabs while the grid is being is loaded in a separate tab.

          In my above mentioned code, tabScreen is the grid class with its own tabscreen.h and tabscreen.cpp files which is independent from other code.

          Can you please help me achieve this functionailty?

          Thanks
          Vidushi

          J Offline
          J Offline
          jsulm
          Lifetime Qt Champion
          wrote on 24 Jan 2017, 05:16 last edited by
          #4

          @vsukhwal As @mrjj said it is not possible to use Qt GUI classes in non main threads.
          Why does it takes so long to create those tabs?
          Do you perform any heavy calculations?
          If so then move those calculations to other threads and pass the results to the UI via signals/slots.

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

          1 Reply Last reply
          2
          • V Offline
            V Offline
            vsukhwal
            wrote on 24 Jan 2017, 17:34 last edited by
            #5

            Most of the time if taken by the http request sending large amount of data. As a result, until the data is not received, the grid cannot be created and updated

            A 1 Reply Last reply 24 Jan 2017, 17:52
            0
            • V vsukhwal
              24 Jan 2017, 17:34

              Most of the time if taken by the http request sending large amount of data. As a result, until the data is not received, the grid cannot be created and updated

              A Offline
              A Offline
              ambershark
              wrote on 24 Jan 2017, 17:52 last edited by
              #6

              @vsukhwal said in New Thread to add new tab when menu item is clicked:

              Most of the time if taken by the http request sending large amount of data. As a result, until the data is not received, the grid cannot be created and updated

              Well that is nice and easy then. Put the data loading/socket communication in a separate thread and when the data is ready update the gui tab.

              My L-GPL'd C++ Logger github.com/ambershark-mike/sharklog

              1 Reply Last reply
              2

              2/6

              23 Jan 2017, 23:08

              topic:navigator.unread, 4
              • Login

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