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. Combining classes - append class to QMainWindow
QtWS25 Last Chance

Combining classes - append class to QMainWindow

Scheduled Pinned Locked Moved Solved General and Desktop
37 Posts 6 Posters 3.0k 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.
  • A Offline
    A Offline
    Anonymous_Banned275
    wrote on 5 Sept 2020, 16:43 last edited by Anonymous_Banned275 9 May 2020, 16:45
    #7

    I did replace the default centerWidget and it works "BETTER".
    Now I have status bar , but Mdi still writes over menubar

       MdiArea *mdiarea = new MdiArea();
        if(centralWidget())
            std::cout <<"TOK centralWidget()  " <<std::endl;
        else
             std::cout <<"FAILED centralWidget()  " <<std::endl;
         setCentralWidget(mdiarea);
    

    f72f277c-dd9e-473e-b767-2d02266457e0-image.png

    J 1 Reply Last reply 6 Sept 2020, 09:07
    0
    • C Offline
      C Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on 5 Sept 2020, 17:11 last edited by
      #8

      Ok, you do have a central widget in designer but it doesn't have a layout (the red crossed circle indicates that), so centralWidget()->layout() is null. That's why it crashed.

      Couple of options:

      1. (That's the one I'd recommend) Delete the central widget in designer and set mdiarea to be it from code:
      setCentralWidget(mdiarea);
      
      1. Add a layout to your central widget in designer and then you can do
      centralWidget()->layout()->addWidget(mdiarea);
      
      1. Add the layout from code and add a widget to it:
      QVBoxLayout* central_widget_layout = new QVBoxLayout(centralWidget());
      central_widget_layout->addWidget(mdiarea);
      

      but Mdi still writes over menubar

      I don't think it does. You just don't have anything in the menubar so it doesn't show up. It will show up once you add some menus or actions to it.

      1 Reply Last reply
      3
      • A Offline
        A Offline
        Anonymous_Banned275
        wrote on 5 Sept 2020, 19:07 last edited by
        #9

        Thanks.
        You solved THREE "problems" in one post !
        I did not realize default QMainWindow form does not have a layout.
        I did not actually know what is "THE LAYOUT" and how it fits into the scheme of things.
        And I'll add some stuff to menu bar to see it .

        Great progress, but I need to fine tune it by adding the "rotten" btscanner dialogue as QDock next...

        S 1 Reply Last reply 5 Sept 2020, 19:13
        0
        • A Anonymous_Banned275
          5 Sept 2020, 19:07

          Thanks.
          You solved THREE "problems" in one post !
          I did not realize default QMainWindow form does not have a layout.
          I did not actually know what is "THE LAYOUT" and how it fits into the scheme of things.
          And I'll add some stuff to menu bar to see it .

          Great progress, but I need to fine tune it by adding the "rotten" btscanner dialogue as QDock next...

          S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 5 Sept 2020, 19:13 last edited by
          #10

          Hi,

          @AnneRanch said in Combining classes - append class to QMainWindow:

          I did not realize default QMainWindow form does not have a layout.

          In fact it does have one and that's why you got the error message when trying to use it. QMainWindow's layout is "protected" because it's it that provides support for dock widgets toolbars etc.

          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
          1
          • A Offline
            A Offline
            Anonymous_Banned275
            wrote on 5 Sept 2020, 23:14 last edited by
            #11

            @Chris-Kawa said in Combining classes - append class to QMainWindow:

            but it doesn't have a layout (the red crossed circle indicates that)

            OK, clarification needed.

            Even AFTER adding "form layout" I still have "red crossed circle" showing in the icon. No errors.

            Having presence or being "protected" seems to be TWO different properties.

            So which one "is causing the problem" encountered?

            1 Reply Last reply
            0
            • A Offline
              A Offline
              Anonymous_Banned275
              wrote on 6 Sept 2020, 00:52 last edited by
              #12

              Expanding on the original post.
              Adding tab class to MainWindow by setting new centralwidget bypasses the missing / private "layout" . That works as desired.

              After that, similar process needs to be done "dowstream" - add QDialog to Tab class. Here the QDialoig does not have "centralwidget" to be replaced.
              So it is back to "layout" which does not exists or is private.

              Or I can go back to original - replacing QDialog with QWidget.
              Prefer no to do so - woudl have to convert more QDialogs to QWidgets.

              Any different solution , similar to centrawidget / layout , would be appreciated.

              J 1 Reply Last reply 6 Sept 2020, 01:30
              0
              • A Anonymous_Banned275
                6 Sept 2020, 00:52

                Expanding on the original post.
                Adding tab class to MainWindow by setting new centralwidget bypasses the missing / private "layout" . That works as desired.

                After that, similar process needs to be done "dowstream" - add QDialog to Tab class. Here the QDialoig does not have "centralwidget" to be replaced.
                So it is back to "layout" which does not exists or is private.

                Or I can go back to original - replacing QDialog with QWidget.
                Prefer no to do so - woudl have to convert more QDialogs to QWidgets.

                Any different solution , similar to centrawidget / layout , would be appreciated.

                J Offline
                J Offline
                JKSH
                Moderators
                wrote on 6 Sept 2020, 01:30 last edited by
                #13

                @AnneRanch said in Combining classes - append class to QMainWindow:

                Here the QDialoig does not have "centralwidget" to be replaced.

                It doesn't indeed. QMainWindow is a special widget with many regions including the "central" region. No other widgets have this structure. See the documentation at https://doc.qt.io/qt-5/qmainwindow.html :

                QMainWindow layout

                So it is back to "layout" which does not exists or is private.

                ...

                Any different solution , similar to centrawidget / layout , would be appreciated.

                Just like you call setCentralWidget() on QMainWindow, you can call setLayout() on plain "container" widgets like QWidget, QDialog, and QGroupBox.

                add QDialog to Tab class

                Can you explain your rationale for doing this?

                A dialog is designed to be a separate pop-up window. A tab widget is for "embedding" other widget inside an existing window. They have opposite goals.

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

                1 Reply Last reply
                4
                • A Anonymous_Banned275
                  5 Sept 2020, 16:43

                  I did replace the default centerWidget and it works "BETTER".
                  Now I have status bar , but Mdi still writes over menubar

                     MdiArea *mdiarea = new MdiArea();
                      if(centralWidget())
                          std::cout <<"TOK centralWidget()  " <<std::endl;
                      else
                           std::cout <<"FAILED centralWidget()  " <<std::endl;
                       setCentralWidget(mdiarea);
                  

                  f72f277c-dd9e-473e-b767-2d02266457e0-image.png

                  J Offline
                  J Offline
                  JonB
                  wrote on 6 Sept 2020, 09:07 last edited by JonB 9 Jun 2020, 09:07
                  #14

                  @AnneRanch
                  Going back for a moment to your earlier screenshot, and something @Chris-Kawa said about it. When using Qt Designer and you look at that "Object/Class" window showing your widget hierarchy: anywhere there you might see any widget you have added showing that "red-crossed-circle no-entry sign" on the widget. That indicates you should right click on that widget and add a layout to it. Without that, your widget layout is liable to be wrong.

                  A 1 Reply Last reply 6 Sept 2020, 17:29
                  2
                  • A Offline
                    A Offline
                    Anonymous_Banned275
                    wrote on 6 Sept 2020, 14:59 last edited by Anonymous_Banned275 9 Jun 2020, 16:09
                    #15

                    Well , not sure if the group wants to continue this discussion.
                    Been chastised for "reinventing wheel ", using stuff DIFFERENTLY than usual etc, Really do not want to repeat that, so let me leave WHY I am doing this alone. Maybe later...

                    I prefer KISS, so my initial approach was to use QtCreator and build , using QtDesigner , base QMainWindow class.
                    I did try QtCreator examples "Application" but it does not use Ui and I was not comfortable modifying "Application" example to fit my goal.

                    However, the QMainWindow class build GUI "form" does not indicate , with the exception (red cross ) I just learn during this discussion, that "layout" is mandatory.

                    That is still unresolved , because AFTER I manually add , using QtDesigner, " form layout " - the "red cross" is still there.

                    As far as using code to reset "centralwidget" I am questioning the necessity of having "layout" - the application GUI works with no specific layout, just "free hand" , which to me makes sense.
                    ( Not sure of advantage of using "form layout" during development - machine second-guessing the location of widgets or vice versa)

                    BUT it looks as adding new QWidget to QMainWindow WITHOUT having "layout" is an issue.
                    ( this format is awkward - I cannot see the previous post to intelligently reply to it )

                    Now back to adding QDialog.
                    I did try to add "layout" using code , but could not find how to code it . I got as far as QLayoutItem. I am still learning to navigate QtCreator.

                     ui->tab->setLayout(????); // test add layout to first tab 
                    

                    PS
                    Here is another, unconventional approach , to similar task
                    https://stackoverflow.com/questions/23676283/splitting-qt-forms-between-multiple-ui-files
                    Just to point out I am not the only crazy one.

                    1 Reply Last reply
                    0
                    • J JonB
                      6 Sept 2020, 09:07

                      @AnneRanch
                      Going back for a moment to your earlier screenshot, and something @Chris-Kawa said about it. When using Qt Designer and you look at that "Object/Class" window showing your widget hierarchy: anywhere there you might see any widget you have added showing that "red-crossed-circle no-entry sign" on the widget. That indicates you should right click on that widget and add a layout to it. Without that, your widget layout is liable to be wrong.

                      A Offline
                      A Offline
                      Anonymous_Banned275
                      wrote on 6 Sept 2020, 17:29 last edited by
                      #16

                      @JonB
                      Do I understand it correctly - adding "layout" to "centralwidget" is not enough to remove the "red cross" ?
                      "layout" needs to be added to any widget "bellow" the "centralwidget".

                      That is pretty minor issue - still looking for an answer why "layout" needs to be used at all when adding widgets in code.

                      P 1 Reply Last reply 6 Sept 2020, 17:56
                      0
                      • C Offline
                        C Offline
                        Chris Kawa
                        Lifetime Qt Champion
                        wrote on 6 Sept 2020, 17:48 last edited by Chris Kawa 9 Jun 2020, 17:49
                        #17

                        Layouts are sort of a geometry managers for child widgets. When you resize a widget its layout takes care of moving and resizing the children to accommodate new parent size.

                        A widget has either no layout or exactly one. This is indicated via that icon we talked about. If a widget has no layout its children sizes and positions are not automatically adjusted and can overlap. In such case you are responsible for manually calling setPos, move, resize, setGeometry or any other similar functions to set a correct child geometry. Layouts are a way of automating this tedious task. If a widget has a layout set it will react to the widgets resizeEvent and adjust children according to the layout's type. For example a QVBoxLayout will place children one under the other. QGridLayout will place them in a grid etc.

                        Now for a little confusing part. You said you added a layout and it didn't remove the red circle. If you did that by dragging a layout from the toolbox on the left like you would with a button or a frame then you didn't set a layout on the widget. You added a new widget with that layout set, so what you have is the original widget, still without layout and a child with that layout.

                        The option to set a layout on a widget is either in the right click menu under the "Lay out" sub-menu or on the toolbar (icons with dots, horizontal and vertical bars). An important note is that designer does not allow to set a layout on a widget that has no children (because it's usually not what you want anyway) so if you don't have any children those options will be grayed out.

                        If you want to do that anyway you can workaround it with these steps:

                        • add any child widget to the widget you want the layout set on (button, frame or whatever)
                        • select the widget you want the layout to be set on
                        • use either the right clik menu or the toolbar icons to set a layout (vertical, horizontal or grid)
                        • remove the child widget you added previously

                        This is not something you usually do though. Usually you either add children and set layout in the designer or do both of those from code.

                        1 Reply Last reply
                        4
                        • A Anonymous_Banned275
                          6 Sept 2020, 17:29

                          @JonB
                          Do I understand it correctly - adding "layout" to "centralwidget" is not enough to remove the "red cross" ?
                          "layout" needs to be added to any widget "bellow" the "centralwidget".

                          That is pretty minor issue - still looking for an answer why "layout" needs to be used at all when adding widgets in code.

                          P Offline
                          P Offline
                          Pl45m4
                          wrote on 6 Sept 2020, 17:56 last edited by Pl45m4 9 Jun 2020, 18:23
                          #18

                          @AnneRanch said in Combining classes - append class to QMainWindow:

                          is not enough to remove the "red cross"

                          It is, but if you do this in code, you will still see the red cross in QtDesigner, because your coded layout applies at run-time.

                          Every widget or widget container can / should have a layout. Otherwise its content is floating around and it will produce other unwanted behavior, in terms of size (resizing) and position (while moving).

                          So every new QMainWindow has its centralWidget, which is empty and has no layout set, per default. You could either add content to it, by drag'n'drop, using QtDesigner and then right click centralWidget -> Layout -> Then pick layout of your choice or you set a layout by using your code, then "grab" that layout again and add widgets (content)

                          QHBoxLayout *cW_Layout = new QHBoxLayout;
                          this->centralWidget->setLayout(cW_Layout);
                          
                          // To access your CW or its layout, do
                          centralWidget->layout()->addWidget(  WIDGET_TO_ADD );
                          
                          // Ofc you can also populate your layout first before adding it to centralWidget
                          

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

                          ~E. W. Dijkstra

                          A 1 Reply Last reply 6 Sept 2020, 22:08
                          0
                          • A Offline
                            A Offline
                            Anonymous_Banned275
                            wrote on 6 Sept 2020, 21:59 last edited by
                            #19

                            I need to restate - I did change / add layout in QtDesigner to observe the red cross persistence.

                            I did not do that in code.

                            As far as layout "automatically " do resizing - I am still in basic app development , hence I am happy camper when I see expected "static" results , I am not in position to move / resize things around at this stage.
                            However, it is nice to know WHY to use layout in future, even it is not of my primary concerns for now.

                            Cheers

                            1 Reply Last reply
                            0
                            • P Pl45m4
                              6 Sept 2020, 17:56

                              @AnneRanch said in Combining classes - append class to QMainWindow:

                              is not enough to remove the "red cross"

                              It is, but if you do this in code, you will still see the red cross in QtDesigner, because your coded layout applies at run-time.

                              Every widget or widget container can / should have a layout. Otherwise its content is floating around and it will produce other unwanted behavior, in terms of size (resizing) and position (while moving).

                              So every new QMainWindow has its centralWidget, which is empty and has no layout set, per default. You could either add content to it, by drag'n'drop, using QtDesigner and then right click centralWidget -> Layout -> Then pick layout of your choice or you set a layout by using your code, then "grab" that layout again and add widgets (content)

                              QHBoxLayout *cW_Layout = new QHBoxLayout;
                              this->centralWidget->setLayout(cW_Layout);
                              
                              // To access your CW or its layout, do
                              centralWidget->layout()->addWidget(  WIDGET_TO_ADD );
                              
                              // Ofc you can also populate your layout first before adding it to centralWidget
                              
                              A Offline
                              A Offline
                              Anonymous_Banned275
                              wrote on 6 Sept 2020, 22:08 last edited by
                              #20

                              @Pl45m4 said in Combining classes - append class to QMainWindow:

                              @AnneRanch said in Combining classes - append class to QMainWindow:

                              is not enough to remove the "red cross"

                              It is, but if you do this in code, you will still see the red cross in QtDesigner, because your coded layout applies at run-time.

                              Every widget or widget container can / should have a layout. Otherwise its content is floating around and it will produce other unwanted behavior, in terms of size (resizing) and position (while moving).

                              So every new QMainWindow has its centralWidget, which is empty and has no layout set, per default. You could either add content to it, by drag'n'drop, using QtDesigner and then right click centralWidget -> Layout -> Then pick layout of your choice or you set a layout by using your code, then "grab" that layout again and add widgets (content)

                              QHBoxLayout *cW_Layout = new QHBoxLayout;
                              this->centralWidget->setLayout(cW_Layout);
                              
                              // To access your CW or its layout, do
                              centralWidget->layout()->addWidget(  WIDGET_TO_ADD );
                              
                              // Ofc you can also populate your layout first before adding it to centralWidget
                              

                              This post is pretty much repeat of what was already said.
                              This is not criticism, just a statement of fact.

                              While applying similar approach in "layout-less" QDialog , as fas as QMianWindow" sees it, I have opted to use "promotion" and it works as desired.

                              Of course the "promoted" form has "layout" already.
                              I hope that makes sense.

                              P 1 Reply Last reply 7 Sept 2020, 02:35
                              -1
                              • A Anonymous_Banned275
                                6 Sept 2020, 22:08

                                @Pl45m4 said in Combining classes - append class to QMainWindow:

                                @AnneRanch said in Combining classes - append class to QMainWindow:

                                is not enough to remove the "red cross"

                                It is, but if you do this in code, you will still see the red cross in QtDesigner, because your coded layout applies at run-time.

                                Every widget or widget container can / should have a layout. Otherwise its content is floating around and it will produce other unwanted behavior, in terms of size (resizing) and position (while moving).

                                So every new QMainWindow has its centralWidget, which is empty and has no layout set, per default. You could either add content to it, by drag'n'drop, using QtDesigner and then right click centralWidget -> Layout -> Then pick layout of your choice or you set a layout by using your code, then "grab" that layout again and add widgets (content)

                                QHBoxLayout *cW_Layout = new QHBoxLayout;
                                this->centralWidget->setLayout(cW_Layout);
                                
                                // To access your CW or its layout, do
                                centralWidget->layout()->addWidget(  WIDGET_TO_ADD );
                                
                                // Ofc you can also populate your layout first before adding it to centralWidget
                                

                                This post is pretty much repeat of what was already said.
                                This is not criticism, just a statement of fact.

                                While applying similar approach in "layout-less" QDialog , as fas as QMianWindow" sees it, I have opted to use "promotion" and it works as desired.

                                Of course the "promoted" form has "layout" already.
                                I hope that makes sense.

                                P Offline
                                P Offline
                                Pl45m4
                                wrote on 7 Sept 2020, 02:35 last edited by Pl45m4 9 Jul 2020, 05:03
                                #21

                                @AnneRanch said in Combining classes - append class to QMainWindow:

                                This post is pretty much repeat of what was already said.

                                If you look at the time stamps of @Chris-Kawa 's and my post, you will see that they are just 2-3mins or so apart. The moment when I started typing, there was no response... So we both wrote our replies at the same time :)


                                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
                                • A Offline
                                  A Offline
                                  Anonymous_Banned275
                                  wrote on 7 Sept 2020, 04:27 last edited by
                                  #22

                                  I think I have painted myself into a corner.

                                  1. I have QMainWindow with class member BT_TabWidget
                                    This part works and I can verify the “connect” too
                                   BT_TabWidget *BT_tab = new BT_TabWidget(this);
                                    setCentralWidget(BT_tab);
                                    connect (BT_tab,
                                             SIGNAL(tabBarClicked(int)),
                                             this,
                                              SLOT(MainTestFunction())
                                             )
                                             ;
                                  
                                  1. In the BT_TabWidget I have promoted “tab” QWidget to
                                    DeviceDiscoveryDialog - QDialog class
                                    This part also works and I can actually retrieve / list bluetooth devices.

                                  2. DeviceDiscovwryDialog class has a member class QBluetoothDeviceDiscoveryAgent
                                    instantiated as
                                    discoveryAgent = new QbluetoothDeviceDiscoveryAgent();
                                    discoveryAgent does all the dirty work and it does it well , so far.

                                  Here is MY problem , basically while trying to monitor the working application progress.

                                  1. I cannot use discoveryAgent , have no access to it , as source for “connect”
                                    I should be able to get intelisense to accept / provide the following
                                    BT_tab→discoveryAgent....
                                    But it gives no "discoveryAget" option.

                                  2. I cannot figure out HOW to include SLOT (QMainWindow(….) ) ,
                                    in “connect” . Again intelisense is of no help and I am not sure if the #1 problem is the cause.
                                    ( I did try &app (main application) - no go )

                                  I am using "discoveryAgent" within the QbluetoothDeviceDiscoveryAgent to track the bluez "library" and just like to extend it to the main "status bar". It worked prior to implementing the promotion scheme.

                                  I am sorry to drag this discussion, but I keep running into these issues in the process.

                                  A P 2 Replies Last reply 7 Sept 2020, 13:58
                                  0
                                  • A Anonymous_Banned275
                                    7 Sept 2020, 04:27

                                    I think I have painted myself into a corner.

                                    1. I have QMainWindow with class member BT_TabWidget
                                      This part works and I can verify the “connect” too
                                     BT_TabWidget *BT_tab = new BT_TabWidget(this);
                                      setCentralWidget(BT_tab);
                                      connect (BT_tab,
                                               SIGNAL(tabBarClicked(int)),
                                               this,
                                                SLOT(MainTestFunction())
                                               )
                                               ;
                                    
                                    1. In the BT_TabWidget I have promoted “tab” QWidget to
                                      DeviceDiscoveryDialog - QDialog class
                                      This part also works and I can actually retrieve / list bluetooth devices.

                                    2. DeviceDiscovwryDialog class has a member class QBluetoothDeviceDiscoveryAgent
                                      instantiated as
                                      discoveryAgent = new QbluetoothDeviceDiscoveryAgent();
                                      discoveryAgent does all the dirty work and it does it well , so far.

                                    Here is MY problem , basically while trying to monitor the working application progress.

                                    1. I cannot use discoveryAgent , have no access to it , as source for “connect”
                                      I should be able to get intelisense to accept / provide the following
                                      BT_tab→discoveryAgent....
                                      But it gives no "discoveryAget" option.

                                    2. I cannot figure out HOW to include SLOT (QMainWindow(….) ) ,
                                      in “connect” . Again intelisense is of no help and I am not sure if the #1 problem is the cause.
                                      ( I did try &app (main application) - no go )

                                    I am using "discoveryAgent" within the QbluetoothDeviceDiscoveryAgent to track the bluez "library" and just like to extend it to the main "status bar". It worked prior to implementing the promotion scheme.

                                    I am sorry to drag this discussion, but I keep running into these issues in the process.

                                    A Offline
                                    A Offline
                                    Anonymous_Banned275
                                    wrote on 7 Sept 2020, 13:58 last edited by
                                    #23

                                    @AnneRanch Here is a thought.
                                    Since promotion works I suspect that promoting QWidget "tab" to "DeviceDiscoveryDialog" is assigning a pointer to the class.
                                    I do not know that pointer, neither does Qt and its intellisence.
                                    Not having access to the unknown pointer I obviously do not have access to "DeviceDiscoveryDialog" variables / methods .

                                    So it is back to QtCreator interaction with QtDesigner - an annoying and BIG issue since I first started looking into Qt.
                                    Perhaps too much behind the scene automation.

                                    I have a small proof.
                                    I can implement promotion to "DeviceDiscoveryDialog" , in dialog, but I have to type /copy it in - no "pull down" control to help me.
                                    However, "DeviceDiscoveryDialog" has to be valid class.
                                    So the QtDesigner have knowledge about the "DeviceDiscoveryDialog", but it cannot be selected via "standard" pull down control.
                                    Unfortunately is it these (little) "gotcha " which keeps project from smooth development and completion.
                                    But it is fun.

                                    1 Reply Last reply
                                    0
                                    • A Anonymous_Banned275
                                      7 Sept 2020, 04:27

                                      I think I have painted myself into a corner.

                                      1. I have QMainWindow with class member BT_TabWidget
                                        This part works and I can verify the “connect” too
                                       BT_TabWidget *BT_tab = new BT_TabWidget(this);
                                        setCentralWidget(BT_tab);
                                        connect (BT_tab,
                                                 SIGNAL(tabBarClicked(int)),
                                                 this,
                                                  SLOT(MainTestFunction())
                                                 )
                                                 ;
                                      
                                      1. In the BT_TabWidget I have promoted “tab” QWidget to
                                        DeviceDiscoveryDialog - QDialog class
                                        This part also works and I can actually retrieve / list bluetooth devices.

                                      2. DeviceDiscovwryDialog class has a member class QBluetoothDeviceDiscoveryAgent
                                        instantiated as
                                        discoveryAgent = new QbluetoothDeviceDiscoveryAgent();
                                        discoveryAgent does all the dirty work and it does it well , so far.

                                      Here is MY problem , basically while trying to monitor the working application progress.

                                      1. I cannot use discoveryAgent , have no access to it , as source for “connect”
                                        I should be able to get intelisense to accept / provide the following
                                        BT_tab→discoveryAgent....
                                        But it gives no "discoveryAget" option.

                                      2. I cannot figure out HOW to include SLOT (QMainWindow(….) ) ,
                                        in “connect” . Again intelisense is of no help and I am not sure if the #1 problem is the cause.
                                        ( I did try &app (main application) - no go )

                                      I am using "discoveryAgent" within the QbluetoothDeviceDiscoveryAgent to track the bluez "library" and just like to extend it to the main "status bar". It worked prior to implementing the promotion scheme.

                                      I am sorry to drag this discussion, but I keep running into these issues in the process.

                                      P Offline
                                      P Offline
                                      Pl45m4
                                      wrote on 7 Sept 2020, 14:45 last edited by Pl45m4 9 Jul 2020, 16:18
                                      #24

                                      @AnneRanch said in Combining classes - append class to QMainWindow:

                                      I cannot use discoveryAgent , have no access to it , as source for “connect”
                                      I should be able to get intelisense to accept / provide the following
                                      BT_tab→discoveryAgent....
                                      But it gives no "discoveryAget" option.

                                      Since discoveryAgent is a var or even a member in your BT_tab widget, you can not just access it from your MainWindow. You could write a getter-function in order to receive a pointer to discoveryAgent inside your MainWindow. You can connect to it afterwards. But there could be better ways in terms of structure. Why you need your agent in MainWindow? You could move every BT task to your BT widget. Then you just need to connect MainWindow and your BT widget for controls. Your Bt widget handles the whole BT stuff.

                                      @AnneRanch said in Combining classes - append class to QMainWindow:

                                      I cannot figure out HOW to include SLOT (QMainWindow(….) ) ,
                                      in “connect” . Again intelisense is of no help and I am not sure if the #1 problem is the cause.
                                      ( I did try &app (main application) - no go )

                                      How to include slot MainWindow?

                                      @AnneRanch said in Combining classes - append class to QMainWindow:

                                      connect (BT_tab,
                                      SIGNAL(tabBarClicked(int)),
                                      this,
                                      SLOT(MainTestFunction())
                                      )
                                      ;

                                      This doesn't look wrong, except you have an int-passing signal, but no slot, that can take that int value (parameter mismatch). Change slot to MainTestFunction(int) or use default values
                                      (void MainWindow::MainTestFunction(int i = 0){ /* some code */ } )

                                      If you use the new signal and slot syntax (function-based instead of string-based with SIGNAL / SLOT keywords), the autocompleter will find your slots (as long as they got declared correctly)
                                      ( https://wiki.qt.io/New_Signal_Slot_Syntax )

                                      connect(BT_tab, &BT_TabWidget::tarBarClicked, this, &MainWindow::MainTestFunction);
                                      

                                      This equals your connection above... 1st and 3rd (sender and receiver instance) stay the same.

                                      • Signal = & + Name of class + :: + name of signal
                                      • Slot = & + Name of class + :: + name of slot (after typing :: it should make some suggestions)

                                      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
                                      • A Offline
                                        A Offline
                                        Anonymous_Banned275
                                        wrote on 7 Sept 2020, 16:44 last edited by
                                        #25

                                        Since discoveryAgent is a var or even a member in your BT_tab widget, you can not just access it from your MainWindow.

                                        Is it not how class relations works?

                                        I have used the "new" connect and it works when the function is declared in QMainWIndow. It helps immensely.

                                        As soon as I can figure out how "bluez" is posting (pairing) error messages I should be able to move them from ( cerr ??) console to main status bar.

                                        Making great progress thanks to this forum.
                                        Appreciate that very much.

                                        P 1 Reply Last reply 7 Sept 2020, 17:24
                                        0
                                        • A Anonymous_Banned275
                                          7 Sept 2020, 16:44

                                          Since discoveryAgent is a var or even a member in your BT_tab widget, you can not just access it from your MainWindow.

                                          Is it not how class relations works?

                                          I have used the "new" connect and it works when the function is declared in QMainWIndow. It helps immensely.

                                          As soon as I can figure out how "bluez" is posting (pairing) error messages I should be able to move them from ( cerr ??) console to main status bar.

                                          Making great progress thanks to this forum.
                                          Appreciate that very much.

                                          P Offline
                                          P Offline
                                          Pl45m4
                                          wrote on 7 Sept 2020, 17:24 last edited by Pl45m4 9 Jul 2020, 17:58
                                          #26

                                          @AnneRanch said in Combining classes - append class to QMainWindow:

                                          Is it not how class relations works?

                                          How should MainWindow know about what happens inside BT_TabWidget unless it's declared public?
                                          So if you create a new QBluetoothDeviceDiscoveryAgent somewhere in your BT_TabWidget, MainWindow will not "see" that and can't access it either.
                                          Besides that I would let your BT widget handle all BT connection stuff and dont try to move the BT device- and connection handling to MainWindow. Connect MainWindow with your BT widget and not with everything inside your BT widget class.

                                          // In MainWindow
                                          connect(this, &MainWindow::someSignal, BT_tab, &BT_TabWidget::startDeviceDiscovery);
                                          
                                          // ############################
                                          
                                          // BT_Widget
                                          // Then search for BT devices in your BT_Widget in "startDeviceDiscovery" slot:
                                          
                                          void BT_Widget::startDeviceDiscovery()
                                          {
                                               QBluetoothDeviceDiscoveryAgent *discoveryAgent = new QBluetoothDeviceDiscoveryAgent(this);
                                                connect(discoveryAgent, SIGNAL(deviceDiscovered(QBluetoothDeviceInfo)),
                                                      this, SLOT(deviceDiscovered(QBluetoothDeviceInfo)));
                                          
                                                 // Start a discovery
                                                 discoveryAgent->start();
                                          
                                                //...
                                          
                                          }
                                          

                                          https://doc.qt.io/qt-5/qbluetoothdevicediscoveryagent.html#details

                                          Edit:

                                          As I've said, I would not use the getter approach in this case (to access BtDiscoveryAgent), but in general, it would look like this:

                                          Class A.h

                                          #include "A.h"
                                          
                                          public:
                                               Class_A();
                                          
                                               A& getA() { return m_A; }
                                          
                                          
                                          private:
                                              A *m_A;
                                          
                                          
                                          

                                          ClassA.cpp

                                          m_A = new A();
                                          

                                          ClassB.h

                                          #include "classA.h"
                                          
                                          public:
                                               Class_B() { classA = new ClassA(); } // Creates ClassA instance in ClassB
                                          
                                          private:
                                              ClassA *classA; // Stores pointer to ClassA in ClassB
                                          
                                          

                                          ClassB.cpp

                                          // get member A from ClassA
                                          A *a = classA->getA();
                                          

                                          ClassA ptr in ClassB is used to access public get-function in ClassA, which will return private member A.
                                          Without getA function, ClassB would NOT see A in ClassA, even though you have full access to that instance (ClassA) itself, because A is a private member (= invisible for other classes).


                                          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

                                          16/37

                                          6 Sept 2020, 17:29

                                          • Login

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