How does the stackedWidget manage its pages?
-
"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?"
-
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 ?
-
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 ?
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.
-
"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?"
@josemarcio15
AQStackedWidget
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. -
@josemarcio15
AQStackedWidget
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.@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.
-
@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.
@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.
-
@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.
@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.
-
@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.
@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 ;) -
@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 ;)@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.
-