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. Multithreading, - widget generation...
QtWS25 Last Chance

Multithreading, - widget generation...

Scheduled Pinned Locked Moved Unsolved General and Desktop
multithreadwidget
9 Posts 5 Posters 1.7k 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.
  • D Offline
    D Offline
    Dariusz
    wrote on 11 Nov 2018, 01:37 last edited by
    #1

    Hey

    Soo I have one of those cool issues... I have a scenario where user can select an x amount of items and at the same time each item could be a parent to 1-5+ items, meaning that a selection of 5 items could result in 45 items selected, each item needs a widget to represent its data, and the widget content can vary, from 5-10 input widgets to 50. As you can see simple selection just turned in to 2250 input widget generation... Now I was running some tests/back and forth and yeah its a bit of a pickle. Each input widget is extended with a "handler" class that connects its output to a proper map so that all data gets updated properly.

    So it does take a little time to generate 1 widget. I was thinking of starting a thread and send a queue of new selections to it every time User would select a new item, but then I remembered... QWidgets can only be created in main thread, which brings me to a point of... well "crap". What do I do now? Can any1 suggest any solution? I'm at loss here :- (

    TIA.

    1 Reply Last reply
    0
    • D Offline
      D Offline
      dheerendra
      Qt Champions 2022
      wrote on 11 Nov 2018, 04:06 last edited by dheerendra 11 Nov 2018, 04:07
      #2

      Are you dynamically creating all the objects(2250) when the selection happens ? Did you check which operation takes time ? It could be that your object creation itself is taking lot of time.

      Dheerendra
      @Community Service
      Certified Qt Specialist
      http://www.pthinks.com

      1 Reply Last reply
      0
      • C Offline
        C Offline
        Christian Ehrlicher
        Lifetime Qt Champion
        wrote on 11 Nov 2018, 08:37 last edited by Christian Ehrlicher 11 Nov 2018, 08:38
        #3

        I wonder how someone could find something useful when he sees 2.5k widgets on a screen. What do you really want to achieve here?
        2.5k widgets on a 1920x1080 - every widget will have only 20x40 px...

        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
        3
        • D Offline
          D Offline
          Dariusz
          wrote on 11 Nov 2018, 08:38 last edited by Dariusz 11 Nov 2018, 09:53
          #4

          As far as I can tell, there is a lot of this that happens in vs cpu usage, but all of it is just qt stuff
          https://pasteboard.co/HME3X4X.png
          So not sure. I'll dig around see if its my objects, but they are rather light. Usually, just a map + connect wrapper.

          @Christian-Ehrlicher Well its not 1920x1080 as screens go up to 4k on average in our work environment and its not uncommon that some users have 2-3 of them. But nevertheless the widgets are stored over top of each other and user only shows 1 widget at a time. However an instance widgets can be generated for each attribute view, meaning that 1 node can be shown in 10 places, requiring 10 input widgets to be instanced - now all of that happens internally but its just the share amount of generation that seems to be the problem - and I havent yet decided to generate widgets on demand as the system is a little complex. Its a lot easier to get a list of attribute views, get their filtered content that they accept and generate a widget per content. & instance it I wish I could just send the task to happen in a separate thread, and once he's done just get a call back with a vector filled with widgets. Then I could allow the user a more "fluent" workflow.

          K 1 Reply Last reply 11 Nov 2018, 10:01
          0
          • D Dariusz
            11 Nov 2018, 08:38

            As far as I can tell, there is a lot of this that happens in vs cpu usage, but all of it is just qt stuff
            https://pasteboard.co/HME3X4X.png
            So not sure. I'll dig around see if its my objects, but they are rather light. Usually, just a map + connect wrapper.

            @Christian-Ehrlicher Well its not 1920x1080 as screens go up to 4k on average in our work environment and its not uncommon that some users have 2-3 of them. But nevertheless the widgets are stored over top of each other and user only shows 1 widget at a time. However an instance widgets can be generated for each attribute view, meaning that 1 node can be shown in 10 places, requiring 10 input widgets to be instanced - now all of that happens internally but its just the share amount of generation that seems to be the problem - and I havent yet decided to generate widgets on demand as the system is a little complex. Its a lot easier to get a list of attribute views, get their filtered content that they accept and generate a widget per content. & instance it I wish I could just send the task to happen in a separate thread, and once he's done just get a call back with a vector filled with widgets. Then I could allow the user a more "fluent" workflow.

            K Offline
            K Offline
            kshegunov
            Moderators
            wrote on 11 Nov 2018, 10:01 last edited by
            #5

            Well, whatever the reason, you can't create or touch widgets in a thread different than the main one (i.e. the GUI thread). You should rethink your design. Either precreate them (which doesn't sound very reasonable), or create on demand.

            Read and abide by the Qt Code of Conduct

            1 Reply Last reply
            1
            • C Offline
              C Offline
              Christian Ehrlicher
              Lifetime Qt Champion
              wrote on 11 Nov 2018, 11:47 last edited by
              #6

              @Dariusz said in Multithreading, - widget generation...:

              But nevertheless the widgets are stored over top of each other and user only shows 1 widget at a time.

              So why not reuse this widget instead creating a lot of stuff which is not needed at all ... you should really rethink the design instead trying to do just create thousands of useless widgets and then wonder why it does not work. If I would create all my widgets on startup it would take ages too...

              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
              0
              • D Offline
                D Offline
                Dariusz
                wrote on 11 Nov 2018, 13:30 last edited by
                #7

                @kshegunov "Either precreate them (which doesn't sound very reasonable), or create on demand." That's what I'm doing now, I'm precalculating them and then displaying. it just I wish that action would happen in other thread, Maybe I can somehow start another QApplication, do it there, then kill application but keep the widgets?

                @Christian-Ehrlicher because depending on type each widget might be instanced to multiple views, meaning that if any of the view user types text it updates all remaining instanced widgets. Its for synchronization. Thats why the current system requires 1 widget per view to be generated. Which mean that there is a lot of generation going on... I wonder, why qt widgets cant be generated in other thread? I take they get added to like "top up most application vector" that stores everything or something, can't that be mutexes or stuff? Weird.

                K 1 Reply Last reply 11 Nov 2018, 15:50
                0
                • D Dariusz
                  11 Nov 2018, 13:30

                  @kshegunov "Either precreate them (which doesn't sound very reasonable), or create on demand." That's what I'm doing now, I'm precalculating them and then displaying. it just I wish that action would happen in other thread, Maybe I can somehow start another QApplication, do it there, then kill application but keep the widgets?

                  @Christian-Ehrlicher because depending on type each widget might be instanced to multiple views, meaning that if any of the view user types text it updates all remaining instanced widgets. Its for synchronization. Thats why the current system requires 1 widget per view to be generated. Which mean that there is a lot of generation going on... I wonder, why qt widgets cant be generated in other thread? I take they get added to like "top up most application vector" that stores everything or something, can't that be mutexes or stuff? Weird.

                  K Offline
                  K Offline
                  kshegunov
                  Moderators
                  wrote on 11 Nov 2018, 15:50 last edited by
                  #8

                  @Dariusz said in Multithreading, - widget generation...:

                  it just I wish that action would happen in other thread

                  Nope. It's simply impossible.

                  Read and abide by the Qt Code of Conduct

                  1 Reply Last reply
                  1
                  • E Offline
                    E Offline
                    Eeli K
                    wrote on 11 Nov 2018, 16:25 last edited by
                    #9

                    Do you mean that the UI should be responsive and the user could do something useful while the widgets are generated and shown one by one? You can probably use a zero timer signal and a slot for that. In this way everything happens in the same thread but the signals created by user interactions are handled between timer signals.

                    1 Reply Last reply
                    0

                    4/9

                    11 Nov 2018, 08:38

                    • Login

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