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. QtDesigner/c++: Is there a way to only instantiate the same component once if it appears across multiple pages?
Forum Updated to NodeBB v4.3 + New Features

QtDesigner/c++: Is there a way to only instantiate the same component once if it appears across multiple pages?

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 3 Posters 419 Views 3 Watching
  • 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
    Jeng22
    wrote on 6 Jun 2019, 18:26 last edited by
    #1

    I have a multi-page application that has some consistent components/widgets across all pages and a different area for different things depending on what page the user is on. All of the pages are made using QtDesigner .ui files and c++. My problem is that I have to instantiate each permanent component on every single c++ class (copy-pasting code) that I use. These components are for getting the current time/date and showing battery life kind of things.

    Is there a way to just instantiate the components once and then have the data carry over across .ui files ?

    Layout example:
    0_1559845177637_f28e2b3b-d89c-4a27-a058-6da5206b3d85-image.png

    Any help/advice is greatly appreciated!

    J 1 Reply Last reply 6 Jun 2019, 22:07
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 6 Jun 2019, 18:35 last edited by
      #2

      Hi,

      Either:
      Make these permanent components independent widgets and reuse them as needed.

      Or just make one of your core widget and make each page an independent widget that you will instanciate and put in that central widget which I guess should be a QStackedWidget.

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

      1 Reply Last reply
      3
      • J Jeng22
        6 Jun 2019, 18:26

        I have a multi-page application that has some consistent components/widgets across all pages and a different area for different things depending on what page the user is on. All of the pages are made using QtDesigner .ui files and c++. My problem is that I have to instantiate each permanent component on every single c++ class (copy-pasting code) that I use. These components are for getting the current time/date and showing battery life kind of things.

        Is there a way to just instantiate the components once and then have the data carry over across .ui files ?

        Layout example:
        0_1559845177637_f28e2b3b-d89c-4a27-a058-6da5206b3d85-image.png

        Any help/advice is greatly appreciated!

        J Offline
        J Offline
        JKSH
        Moderators
        wrote on 6 Jun 2019, 22:07 last edited by
        #3

        @SGaist said in QtDesigner/c++: Is there a way to only instantiate the same component once if it appears across multiple pages?:

        Or just make one of your core widget and make each page an independent widget that you will instanciate and put in that central widget which I guess should be a QStackedWidget.

        To clarify @SGaist's 2nd point:

        • Put your permanent components directly in the central widget of the Main Window. Do not put them in your individual pages.
        • Implement your "Different Display" as a QStackedWidget and add your individual pages to the stacked widget.

        Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

        1 Reply Last reply
        3
        • J Offline
          J Offline
          Jeng22
          wrote on 7 Jun 2019, 19:07 last edited by
          #4

          Hi,

          Thanks to both of you. That cleared things up, I got what I was looking for.

          Thanks!

          1 Reply Last reply
          0

          1/4

          6 Jun 2019, 18:26

          • Login

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