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. How does the stackedWidget manage its pages?
QtWS25 Last Chance

How does the stackedWidget manage its pages?

Scheduled Pinned Locked Moved Solved General and Desktop
9 Posts 4 Posters 445 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.
  • J Offline
    J Offline
    josemarcio15
    wrote on 16 Jun 2024, 05:59 last edited by
    #1

    "Let me clarify further, I want to create a QtWidgets application using stackedWidget, and in this app, it would be a digital book, containing hundreds or even thousands of chapters (just to understand, not that the book actually contains so many chapters). My question is, will the stackedWidget load all the contained pages, or will it load dynamically? By default. Should I be concerned about processing power or RAM usage?"

    J 1 Reply Last reply 17 Jun 2024, 16:34
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 16 Jun 2024, 06:51 last edited by
      #2

      Hi,

      If you are thinking about loading each and every page in its own widget, I would say your design is flawed.

      What is the file format for your book ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      J 1 Reply Last reply 17 Jun 2024, 14:56
      1
      • S SGaist
        16 Jun 2024, 06:51

        Hi,

        If you are thinking about loading each and every page in its own widget, I would say your design is flawed.

        What is the file format for your book ?

        J Offline
        J Offline
        josemarcio15
        wrote on 17 Jun 2024, 14:56 last edited by
        #3

        @SGaist

        I don't know yet if I will use PDF or TXT; for now, I have used .txt for testing.

        My idea was to load each chapter of the book; for example, in the interface, I want to use a stacked widget to navigate through the chapters, and when selecting the chapter, it loads the specific .txt file. The stacked widget will be just to organize the number of chapters and topics. I'm just starting to program and don't know the best way yet; if you could give me the steps, I would appreciate it. I tried to make separate .ui files but didn't find it a good idea.

        1 Reply Last reply
        0
        • J josemarcio15
          16 Jun 2024, 05:59

          "Let me clarify further, I want to create a QtWidgets application using stackedWidget, and in this app, it would be a digital book, containing hundreds or even thousands of chapters (just to understand, not that the book actually contains so many chapters). My question is, will the stackedWidget load all the contained pages, or will it load dynamically? By default. Should I be concerned about processing power or RAM usage?"

          J Offline
          J Offline
          JonB
          wrote on 17 Jun 2024, 16:34 last edited by
          #4

          @josemarcio15
          A QStackedWidget gives you a convenient means of displaying one of a number of widgets at a time. But if you preload it with "thousands" of objects/pages/chapters/whatever then those would all be held in memory; although the stacked widget would only display one of them, the text of the others would still be in RAM. It does "display" management but not "memory" management.

          If you have a "large" amount of data and are concerned about memory it would be your job to, say, read individual items from backing store, show, then "free" them from memory if you want to control/reduce memory. If they were in, say, QSqlDatabase this could be done. Or by other code if they are in disk files or available a page at a time from a PDF file.

          J 1 Reply Last reply 18 Jun 2024, 04:28
          2
          • J JonB
            17 Jun 2024, 16:34

            @josemarcio15
            A QStackedWidget gives you a convenient means of displaying one of a number of widgets at a time. But if you preload it with "thousands" of objects/pages/chapters/whatever then those would all be held in memory; although the stacked widget would only display one of them, the text of the others would still be in RAM. It does "display" management but not "memory" management.

            If you have a "large" amount of data and are concerned about memory it would be your job to, say, read individual items from backing store, show, then "free" them from memory if you want to control/reduce memory. If they were in, say, QSqlDatabase this could be done. Or by other code if they are in disk files or available a page at a time from a PDF file.

            J Offline
            J Offline
            josemarcio15
            wrote on 18 Jun 2024, 04:28 last edited by
            #5

            @JonB I understand, thank you very much for clearing up my doubt. Ideally, it would be best to load only 1 or 2 subsequent chapters to avoid performance loss. I thought QStackedWidget would handle this memory management. But now I know where to start.

            S 1 Reply Last reply 18 Jun 2024, 20:56
            0
            • J josemarcio15
              18 Jun 2024, 04:28

              @JonB I understand, thank you very much for clearing up my doubt. Ideally, it would be best to load only 1 or 2 subsequent chapters to avoid performance loss. I thought QStackedWidget would handle this memory management. But now I know where to start.

              S Offline
              S Offline
              SGaist
              Lifetime Qt Champion
              wrote on 18 Jun 2024, 20:56 last edited by
              #6

              @josemarcio15 you can see QStackedWidget as a container. If you pour 10000 widgets in it, it won't do anything special with regard to memory handling of them because it's not its job. Its job is to put all these widgets in a single place and allow you to switch them "in view" one at a time. There will be no rendering done from the widgets underneath which will save on CPU and possibly some RAM but again it's not due to QStackedWidget itself.

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              J 1 Reply Last reply 21 Jun 2024, 18:05
              2
              • S SGaist
                18 Jun 2024, 20:56

                @josemarcio15 you can see QStackedWidget as a container. If you pour 10000 widgets in it, it won't do anything special with regard to memory handling of them because it's not its job. Its job is to put all these widgets in a single place and allow you to switch them "in view" one at a time. There will be no rendering done from the widgets underneath which will save on CPU and possibly some RAM but again it's not due to QStackedWidget itself.

                J Offline
                J Offline
                josemarcio15
                wrote on 21 Jun 2024, 18:05 last edited by
                #7

                @SGaist Thank you for your time, now I know where to start thanks to you. Lastly, so I don't have to keep asking you so much, besides the documentation, is there any tutorial you know of that I could study these application structures? I want to delve deeper into Qt, as it seems like a great choice for me because it supports multiple platforms, and I can't find very detailed content.

                M 1 Reply Last reply 21 Jun 2024, 18:33
                0
                • J josemarcio15
                  21 Jun 2024, 18:05

                  @SGaist Thank you for your time, now I know where to start thanks to you. Lastly, so I don't have to keep asking you so much, besides the documentation, is there any tutorial you know of that I could study these application structures? I want to delve deeper into Qt, as it seems like a great choice for me because it supports multiple platforms, and I can't find very detailed content.

                  M Offline
                  M Offline
                  mpergand
                  wrote on 21 Jun 2024, 18:33 last edited by mpergand
                  #8

                  @josemarcio15 said in How does the stackedWidget manage its pages?:

                  is there any tutorial you know of that I could study these application structures?

                  Hi,

                  Basically in your case, a TreeView for the table of contents and a view to display pages.
                  You have to manage change of pages, by clicking in the treeview and by keyboard press or shortcuts.

                  The last question is: how long does it take to load a page ?
                  If it takes too long, you will have to implement preloading/catching mecanism.
                  Not really a big deal and pretty good exercice for beginners ;)

                  J 1 Reply Last reply 23 Jun 2024, 03:41
                  1
                  • M mpergand
                    21 Jun 2024, 18:33

                    @josemarcio15 said in How does the stackedWidget manage its pages?:

                    is there any tutorial you know of that I could study these application structures?

                    Hi,

                    Basically in your case, a TreeView for the table of contents and a view to display pages.
                    You have to manage change of pages, by clicking in the treeview and by keyboard press or shortcuts.

                    The last question is: how long does it take to load a page ?
                    If it takes too long, you will have to implement preloading/catching mecanism.
                    Not really a big deal and pretty good exercice for beginners ;)

                    J Offline
                    J Offline
                    josemarcio15
                    wrote on 23 Jun 2024, 03:41 last edited by
                    #9

                    @mpergand Thank you for the tip, but my book doesn't have a lot of content to load into a txt file. In fact, it consists of hundreds of short chapters, so loading doesn't take much time. I've divided it so that it opens one chapter at a time, specifically to make it quick when loading a chapter. But thank you for the advice; when I need it, I'll use 'preloading/caching'. As mentioned earlier, I want to learn the best way and avoid going down wrong paths only to have to correct them later.

                    1 Reply Last reply
                    0
                    • J josemarcio15 has marked this topic as solved on 23 Jun 2024, 03:42

                    7/9

                    21 Jun 2024, 18:05

                    • Login

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