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 to create relation between main ui and different cpp/h files?
Forum Updated to NodeBB v4.3 + New Features

How to create relation between main ui and different cpp/h files?

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 4 Posters 327 Views 1 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.
  • R Offline
    R Offline
    Rozerin YILDIZ
    wrote on last edited by
    #1

    I am newby in QT. I want to create a desktop project using QT widget app c++. In my mainwindow ui, there are multiple layouts and frames for each layout. For instance, for one of frame i use a listwidget. I add items here in mainwindow.cpp. Then, click one of item it sholud create a chart. I created a qchart in a different frame. I use mainwindow.cpp either for creating qchart. But i have more frames. If i use mainwindow.cpp for everything it can be a problem. I don't know how to create a relation between new cpp/h files and mainwindow ui. I use just one page for this desktop app. So, if i need to create new cpp/h files how can i add something (like qlistwidget items, qchart ...) to one of mainwindow frame (or layout)?

    C jsulmJ 2 Replies Last reply
    0
    • R Rozerin YILDIZ

      I am newby in QT. I want to create a desktop project using QT widget app c++. In my mainwindow ui, there are multiple layouts and frames for each layout. For instance, for one of frame i use a listwidget. I add items here in mainwindow.cpp. Then, click one of item it sholud create a chart. I created a qchart in a different frame. I use mainwindow.cpp either for creating qchart. But i have more frames. If i use mainwindow.cpp for everything it can be a problem. I don't know how to create a relation between new cpp/h files and mainwindow ui. I use just one page for this desktop app. So, if i need to create new cpp/h files how can i add something (like qlistwidget items, qchart ...) to one of mainwindow frame (or layout)?

      C Offline
      C Offline
      ChrisW67
      wrote on last edited by ChrisW67
      #2

      @Rozerin-YILDIZ Lots of options, but I am not sure I understand the question. Can you write a list of steps the user takes and what they should see, or draw a picture of what you want to happen?

      Something like:

      • User launches app.
        • See main window with bunch of buttons and a QTabWidget in a layout.
      • User clicks "Foobar" button.
        • See new tab in QTabWidget
        • Tab displays a BarBazWidget defined in barbaz.{h,cpp}
      • Or user clicks "Foobar" button.
        • Sees new window. Original window stays visible
        • New window displays a BarBazWidget defined in barbaz.{h,cpp}
      • Or user clicks "Foobar" button.
        • Original window stays visible
        • Space previously occupied by a table is replaced with a BarBazWidget defined in barbaz.{h,cpp}
        • Original table is discarded/kept
      R 1 Reply Last reply
      0
      • R Rozerin YILDIZ

        I am newby in QT. I want to create a desktop project using QT widget app c++. In my mainwindow ui, there are multiple layouts and frames for each layout. For instance, for one of frame i use a listwidget. I add items here in mainwindow.cpp. Then, click one of item it sholud create a chart. I created a qchart in a different frame. I use mainwindow.cpp either for creating qchart. But i have more frames. If i use mainwindow.cpp for everything it can be a problem. I don't know how to create a relation between new cpp/h files and mainwindow ui. I use just one page for this desktop app. So, if i need to create new cpp/h files how can i add something (like qlistwidget items, qchart ...) to one of mainwindow frame (or layout)?

        jsulmJ Offline
        jsulmJ Offline
        jsulm
        Lifetime Qt Champion
        wrote on last edited by
        #3

        @Rozerin-YILDIZ said in How to create relation between main ui and different cpp/h files?:

        So, if i need to create new cpp/h files how can i add something (like qlistwidget items, qchart ...) to one of mainwindow frame (or layout)?

        See https://doc.qt.io/qt-6/designer-using-custom-widgets.html
        You create a custom widget in other ui/h/cpp files and then in main window you add a normal QWdget and then use the "promote" feature to replace this QWidget with your own custom widget.

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

        1 Reply Last reply
        0
        • C ChrisW67

          @Rozerin-YILDIZ Lots of options, but I am not sure I understand the question. Can you write a list of steps the user takes and what they should see, or draw a picture of what you want to happen?

          Something like:

          • User launches app.
            • See main window with bunch of buttons and a QTabWidget in a layout.
          • User clicks "Foobar" button.
            • See new tab in QTabWidget
            • Tab displays a BarBazWidget defined in barbaz.{h,cpp}
          • Or user clicks "Foobar" button.
            • Sees new window. Original window stays visible
            • New window displays a BarBazWidget defined in barbaz.{h,cpp}
          • Or user clicks "Foobar" button.
            • Original window stays visible
            • Space previously occupied by a table is replaced with a BarBazWidget defined in barbaz.{h,cpp}
            • Original table is discarded/kept
          R Offline
          R Offline
          Rozerin YILDIZ
          wrote on last edited by
          #4

          @ChrisW67 Let's say this is the main window:
          0c1f956c-cd73-40d3-a246-e9a0987c0855-image.png

          As you can see, there are multiple frames (layouts) in main window. For instance, there is a qlistwidget in frame 1. If click one of list item, then there will be a qchart in frame 2. That's the story. I wrote this code in mainwindow.cpp and it works, no problem. But for other frames, i will need create something like this. That's why there will be many issues in a one cpp file. I want to split this issues (if it makes sense). There will be just one .ui file (mainwindow.ui). I hope i can be clear enough. Thank you.

          Pl45m4P 1 Reply Last reply
          0
          • R Rozerin YILDIZ

            @ChrisW67 Let's say this is the main window:
            0c1f956c-cd73-40d3-a246-e9a0987c0855-image.png

            As you can see, there are multiple frames (layouts) in main window. For instance, there is a qlistwidget in frame 1. If click one of list item, then there will be a qchart in frame 2. That's the story. I wrote this code in mainwindow.cpp and it works, no problem. But for other frames, i will need create something like this. That's why there will be many issues in a one cpp file. I want to split this issues (if it makes sense). There will be just one .ui file (mainwindow.ui). I hope i can be clear enough. Thank you.

            Pl45m4P Online
            Pl45m4P Online
            Pl45m4
            wrote on last edited by Pl45m4
            #5

            @Rozerin-YILDIZ said in How to create relation between main ui and different cpp/h files?:

            There will be just one .ui file (mainwindow.ui)

            The UI file is not directly connected to your class structure... As you might know, you don't need any *.ui files at all. Everything can be done by code.

            I want to split this issues (if it makes sense)

            Make no sense to me to split the MainWindow content into multiple classes / files. If it's shown (used only) in your MainWindow widget, what's wrong with having the code there?
            QMainWindow after all is just another widget, that you can fill with content.

            As I've said in your other topic, you can make widget "factories" to create and return the new widget to your main window.
            But this is also not needed.

            And if you subsclass some widget, you have your own separate class (files) anyway, which you include in your MainWindow header or code file.


            If debugging is the process of removing software bugs, then programming must be the process of putting them in.

            ~E. W. Dijkstra

            1 Reply Last reply
            0

            • Login

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