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
Forum Update on Monday, May 27th 2025

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.
  • 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
                      • A Offline
                        A Offline
                        Anonymous_Banned275
                        wrote on 8 Sept 2020, 15:32 last edited by
                        #27

                        This will certainly look repetitious to the discussion, but I AM Still having this issue.

                        All of my "connect" code originally codded in QDialog of btscanner work as expected. No problem.

                        What I desire is to post a message to QMainWindow "status bar".
                        In theory , I want to "connect" former object QDialog to object QWidget.

                        So I am adding another "connect" to the working code - constructor - of DeviceDiscoveryDialog.

                        The sender SIGNAL object is "ui->scan" - plain "push button" and "ui->scan"
                        does triple duty as part of mentioned other working "connect".

                        The "issue" is , and again I asked before , HOW to assign (syntax) receiver object as QMainWindow.
                        ( I believe my otherwise working code structure Main window -> tab widget ->DeviceDiscoveryDialog-> buetooth -QBuletoothDeviceDiscoveryAgent is OK)

                        `
                        if(
                        (bool)
                        connect( ui->scan,
                        SIGNAL( sendStatus( const QString & ) ),
                        &MainWindow_BT(),
                        SLOT(MainWindow_BT()::displayStatusMessage(const QString & )
                        )
                        )
                        )

                        Above included code snippet throws this error 
                        
                        
                        

                        /media/z/DEV_COPY_LABEL/Qt/QT/qtconnectivity/examples/bluetooth/CAT_BT/device.cpp:136: error: taking address of temporary [-fpermissive]
                        &MainWindow_BT(),
                        ^

                        What am I doing wrong ? 
                        
                        PS 
                        I need to pass message using "connect" which implies, per doc,  I Ishould not be using the "new" connect style to connect functions.  At leas not WITHOUT more knowledge HOW to add parameters ( QString) to the "connect" process functions in new style of connect. 
                        Maybe  later.
                        P 1 Reply Last reply 8 Sept 2020, 18:33
                        0
                        • S Offline
                          S Offline
                          SGaist
                          Lifetime Qt Champion
                          wrote on 8 Sept 2020, 16:04 last edited by
                          #28

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

                          &MainWindow_BT(),

                          You are creating a temporary object and taking its address.

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

                          SLOT(MainWindow_BT()::displayStatusMessage(const QString & )

                          This is wrong as well. It's the slot name that is required.

                          In any case, this code looks like it's located in a dialog that is likely created any your MainWindow_BT class. Is that correct ? If so, you are doing the connection in the wrong object. Your dialog should send its status and not care who is receiving it. That code should be located in the class that creates and handles your DeviceDiscoveryDialog. Likely your MainWindow_BT class.

                          Therefore:

                          connect(pointer_to_dialog, &DeviceDiscoveryDialog::sendStatus, this, &MainWindow_BT::displayStatusMessage);
                          

                          I do not see in your PS the relation with the new syntax.

                          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
                          • A Anonymous_Banned275
                            8 Sept 2020, 15:32

                            This will certainly look repetitious to the discussion, but I AM Still having this issue.

                            All of my "connect" code originally codded in QDialog of btscanner work as expected. No problem.

                            What I desire is to post a message to QMainWindow "status bar".
                            In theory , I want to "connect" former object QDialog to object QWidget.

                            So I am adding another "connect" to the working code - constructor - of DeviceDiscoveryDialog.

                            The sender SIGNAL object is "ui->scan" - plain "push button" and "ui->scan"
                            does triple duty as part of mentioned other working "connect".

                            The "issue" is , and again I asked before , HOW to assign (syntax) receiver object as QMainWindow.
                            ( I believe my otherwise working code structure Main window -> tab widget ->DeviceDiscoveryDialog-> buetooth -QBuletoothDeviceDiscoveryAgent is OK)

                            `
                            if(
                            (bool)
                            connect( ui->scan,
                            SIGNAL( sendStatus( const QString & ) ),
                            &MainWindow_BT(),
                            SLOT(MainWindow_BT()::displayStatusMessage(const QString & )
                            )
                            )
                            )

                            Above included code snippet throws this error 
                            
                            
                            

                            /media/z/DEV_COPY_LABEL/Qt/QT/qtconnectivity/examples/bluetooth/CAT_BT/device.cpp:136: error: taking address of temporary [-fpermissive]
                            &MainWindow_BT(),
                            ^

                            What am I doing wrong ? 
                            
                            PS 
                            I need to pass message using "connect" which implies, per doc,  I Ishould not be using the "new" connect style to connect functions.  At leas not WITHOUT more knowledge HOW to add parameters ( QString) to the "connect" process functions in new style of connect. 
                            Maybe  later.
                            P Offline
                            P Offline
                            Pl45m4
                            wrote on 8 Sept 2020, 18:33 last edited by
                            #29

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

                            This will certainly look repetitious to the discussion, but I AM Still having this issue.

                            But you still make the same mistakes :)

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

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

                            It's always this structure. So no () - function calls in second or fourth argument allowed.

                            My Get-Example was to illustrate how it would look like, when accessing private members from another class.

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

                            I need to pass message using "connect" which implies, per doc, I Ishould not be using the "new" connect style to connect functions. At leas not WITHOUT more knowledge HOW to add parameters ( QString) to the "connect" process functions in new style of connect.
                            Maybe later.

                            You dont need to use arguments in connection statement. The new syntax will do that for you. If your signal passes QString and your slot accepts QString, it just works. So you don't have to worry about types in your connection, if they match, everything's fine.

                            This

                            connect(test, SIGNAL(someSignal(QString)), this, SLOT(randomFnctn(QString)));
                            

                            Or even that:

                            connect(test, SIGNAL(someSignal(int, qreal, QVector<int>)), this, SLOT(randomFnctn(int, qreal, QVector<int>)));
                            

                            Equals this:

                            connect(test, &TestWidget::someSignal, this, &MainWindow::randomFnctn);
                            

                            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 9 Sept 2020, 00:52 last edited by
                              #30

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

                              Equals this:
                              connect(test, &TestWidget::someSignal, this, &MainWindow::randomFnctn);

                              Please note - I may be repeating my errors but I do not post just to get "cut and paste" confirmations of my posts.
                              I am hoping somebody will help find / lead me to a solution.
                              .

                              Here is a faulty - need of solution - code snippet .

                              DeviceDiscoveryDialog::DeviceDiscoveryDialog(QWidget *parent)
                                  :   QDialog(parent), localDevice(new QBluetoothLocalDevice),
                                    ui(new Ui_DeviceDiscovery)
                              {
                                 ui->setupUi(this);
                                 discoveryAgent = new QBluetoothDeviceDiscoveryAgent();
                              // working connect 
                                  connect(ui->scan, SIGNAL(clicked()), this, SLOT(startScan()));
                              // faulty connect 
                              both sendStatus and displayStatusMessage are given/ completed by intellisnese - they exists,  and are valid BUT 
                              this code throws  an error 
                                  connect(ui->scan,
                                          &DeviceDiscoveryDialog::sendStatus,
                                          this,
                                          &MainWindow_BT::displayStatusMessage);
                              

                              **Compiler output AFTERT "no matching function" error

                              &MainWindow_BT::displayStatusMessage);
                              

                              is declared**

                              This is just " connect" error, I have NOT implemented the actual "emit" to use it. Not until it passes by complier.

                              ../CAT_BT/device.cpp: In constructor 'DeviceDiscoveryDialog::DeviceDiscoveryDialog(QWidget*)':
                              ../CAT_BT/device.cpp:121:49: error: no matching function for call to 'DeviceDiscoveryDialog::connect(QPushButton*&, void (DeviceDiscoveryDialog::*)(const QString&), DeviceDiscoveryDialog*, void (MainWindow_BT::*)(const QString&))'
                                           &MainWindow_BT::displayStatusMessage);
                                                                               ^
                              In file included from /usr/include/x86_64-linux-gnu/qt5/QtCore/qvariant.h:45:0,
                                               from /usr/include/x86_64-linux-gnu/qt5/QtCore/QVariant:1,
                                               from .uic/ui_device.h:12,
                                               from ../CAT_BT/device.h:56,
                                               from ../CAT_BT/device.cpp:51:
                              /usr/include/x86_64-linux-gnu/qt5/QtCore/qobject.h:196:36: note: candidate: static QMetaObject::Connection QObject::connect(const QObject*, const char*, const QObject*, const char*, Qt::ConnectionType)
                                   static QMetaObject::Connection connect(const QObject *sender, const char *signal,
                                                                  ^
                              /usr/include/x86_64-linux-gnu/qt5/QtCore/qobject.h:196:36: note:   no known conversion for argument 2 from 'void (DeviceDiscoveryDialog::*)(const QString&)' to 'const char*'
                              /usr/include/x86_64-linux-gnu/qt5/QtCore/qobject.h:199:36: note: candidate: static QMetaObject::Connection QObject::connect(const QObject*, const QMetaMethod&, const QObject*, const QMetaMethod&, Qt::ConnectionType)
                                   static QMetaObject::Connection connect(const QObject *sender, const QMetaMethod &signal,
                                                                  ^
                              /usr/include/x86_64-linux-gnu/qt5/QtCore/qobject.h:199:36: note:   no known conversion for argument 2 from 'void (DeviceDiscoveryDialog::*)(const QString&)' to 'const QMetaMethod&'
                              /usr/include/x86_64-linux-gnu/qt5/QtCore/qobject.h:475:32: note: candidate: QMetaObject::Connection QObject::connect(const QObject*, const char*, const char*, Qt::ConnectionType) const
                               inline QMetaObject::Connection QObject::connect(const QObject *asender, const char *asignal,
                                                              ^
                              /usr/include/x86_64-linux-gnu/qt5/QtCore/qobject.h:475:32: note:   no known conversion for argument 2 from 'void (DeviceDiscoveryDialog::*)(const QString&)' to 'const char*'
                              /usr/include/x86_64-linux-gnu/qt5/QtCore/qobject.h:213:43: note: candidate: static QMetaObject::Connection QObject::connect(const typename QtPrivate::FunctionPointer<Func>::Object*, Func1, const typename QtPrivate::FunctionPointer<Func2>::Object*, Func2, Qt::ConnectionType) [with Func1 = void (DeviceDiscoveryDialog::*)(const QString&); Func2 = void (MainWindow_BT::*)(const QString&); typename QtPrivate::FunctionPointer<Func>::Object = DeviceDiscoveryDialog; typename QtPrivate::FunctionPointer<Func2>::Object = MainWindow_BT]
                                   static inline QMetaObject::Connection connect(const typename QtPrivate::FunctionPointer<Func1>::Object *sender, Func1 signal,
                                                                         ^
                              /usr/include/x86_64-linux-gnu/qt5/QtCore/qobject.h:213:43: note:   no known conversion for argument 1 from 'QPushButton*' to 'const Object* {aka const DeviceDiscoveryDialog*}'
                              /usr/include/x86_64-linux-gnu/qt5/QtCore/qobject.h:245:13: note: candidate: template<class Func1, class Func2> static typename QtPrivate::QEnableIf<((int)(QtPrivate::FunctionPointer<Func2>::ArgumentCount) >= 0), QMetaObject::Connection>::Type QObject::connect(const typename QtPrivate::FunctionPointer<Func>::Object*, Func1, Func2)
                                           connect(const typename QtPrivate::FunctionPointer<Func1>::Object *sender, Func1 signal, Func2 slot)
                                           ^
                              /usr/include/x86_64-linux-gnu/qt5/QtCore/qobject.h:245:13: note:   template argument deduction/substitution failed:
                              ../CAT_BT/device.cpp:121:49: note:   candidate expects 3 arguments, 4 provided
                                           &MainWindow_BT::displayStatusMessage);
                                                                               ^
                              In file included from /usr/include/x86_64-linux-gnu/qt5/QtCore/qvariant.h:45:0,
                                               from /usr/include/x86_64-linux-gnu/qt5/QtCore/QVariant:1,
                                               from .uic/ui_device.h:12,
                                               from ../CAT_BT/device.h:56,
                                               from ../CAT_BT/device.cpp:51:
                              /usr/include/x86_64-linux-gnu/qt5/QtCore/qobject.h:254:13: note: candidate: template<class Func1, class Func2> static typename QtPrivate::QEnableIf<(((int)(QtPrivate::FunctionPointer<Func2>::ArgumentCount) >= 0) && (! QtPrivate::FunctionPointer<Func2>::IsPointerToMemberFunction)), QMetaObject::Connection>::Type QObject::connect(const typename QtPrivate::FunctionPointer<Func>::Object*, Func1, const QObject*, Func2, Qt::ConnectionType)
                                           connect(const typename QtPrivate::FunctionPointer<Func1>::Object *sender, Func1 signal, const QObject *context, Func2 slot,
                                           ^
                              /usr/include/x86_64-linux-gnu/qt5/QtCore/qobject.h:254:13: note:   template argument deduction/substitution failed:
                              /usr/include/x86_64-linux-gnu/qt5/QtCore/qobject.h: In substitution of 'template<class Func1, class Func2> static typename QtPrivate::QEnableIf<(((int)(QtPrivate::FunctionPointer<Func2>::ArgumentCount) >= 0) && (! QtPrivate::FunctionPointer<Func2>::IsPointerToMemberFunction)), QMetaObject::Connection>::Type QObject::connect(const typename QtPrivate::FunctionPointer<Func>::Object*, Func1, const QObject*, Func2, Qt::ConnectionType) [with Func1 = void (DeviceDiscoveryDialog::*)(const QString&); Func2 = void (MainWindow_BT::*)(const QString&)]':
                              ../CAT_BT/device.cpp:121:49:   required from here
                              /usr/include/x86_64-linux-gnu/qt5/QtCore/qobject.h:254:13: error: invalid use of incomplete type 'struct QtPrivate::QEnableIf<false, QMetaObject::Connection>'
                              In file included from /usr/include/x86_64-linux-gnu/qt5/QtCore/qatomic.h:34:0,
                                               from /usr/include/x86_64-linux-gnu/qt5/QtCore/qvariant.h:37,
                                               from /usr/include/x86_64-linux-gnu/qt5/QtCore/QVariant:1,
                                               from .uic/ui_device.h:12,
                                               from ../CAT_BT/device.h:56,
                                               from ../CAT_BT/device.cpp:51:
                              /usr/include/x86_64-linux-gnu/qt5/QtCore/qglobal.h:1073:45: note: declaration of 'struct QtPrivate::QEnableIf<false, QMetaObject::Connection>'
                               template <bool B, typename T = void> struct QEnableIf;
                                                                           ^
                              In file included from /usr/include/x86_64-linux-gnu/qt5/QtCore/qvariant.h:45:0,
                                               from /usr/include/x86_64-linux-gnu/qt5/QtCore/QVariant:1,
                                               from .uic/ui_device.h:12,
                                               from ../CAT_BT/device.h:56,
                                               from ../CAT_BT/device.cpp:51:
                              /usr/include/x86_64-linux-gnu/qt5/QtCore/qobject.h:285:13: note: candidate: template<class Func1, class Func2> static typename QtPrivate::QEnableIf<(QtPrivate::FunctionPointer<Func2>::ArgumentCount == (-1)), QMetaObject::Connection>::Type QObject::connect(const typename QtPrivate::FunctionPointer<Func>::Object*, Func1, Func2)
                                           connect(const typename QtPrivate::FunctionPointer<Func1>::Object *sender, Func1 signal, Func2 slot)
                                           ^
                              /usr/include/x86_64-linux-gnu/qt5/QtCore/qobject.h:285:13: note:   template argument deduction/substitution failed:
                              ../CAT_BT/device.cpp:121:49: note:   candidate expects 3 arguments, 4 provided
                                           &MainWindow_BT::displayStatusMessage);
                                                                               ^
                              In file included from /usr/include/x86_64-linux-gnu/qt5/QtCore/qvariant.h:45:0,
                                               from /usr/include/x86_64-linux-gnu/qt5/QtCore/QVariant:1,
                                               from .uic/ui_device.h:12,
                                               from ../CAT_BT/device.h:56,
                                               from ../CAT_BT/device.cpp:51:
                              /usr/include/x86_64-linux-gnu/qt5/QtCore/qobject.h:293:13: note: candidate: template<class Func1, class Func2> static typename QtPrivate::QEnableIf<(QtPrivate::FunctionPointer<Func2>::ArgumentCount == (-1)), QMetaObject::Connection>::Type QObject::connect(const typename QtPrivate::FunctionPointer<Func>::Object*, Func1, const QObject*, Func2, Qt::ConnectionType)
                                           connect(const typename QtPrivate::FunctionPointer<Func1>::Object *sender, Func1 signal, const QObject *context, Func2 slot,
                                           ^
                              /usr/include/x86_64-linux-gnu/qt5/QtCore/qobject.h:293:13: note:   template argument deduction/substitution failed:
                              /usr/include/x86_64-linux-gnu/qt5/QtCore/qobject.h: In substitution of 'template<class Func1, class Func2> static typename QtPrivate::QEnableIf<(QtPrivate::FunctionPointer<Func2>::ArgumentCount == (-1)), QMetaObject::Connection>::Type QObject::connect(const typename QtPrivate::FunctionPointer<Func>::Object*, Func1, const QObject*, Func2, Qt::ConnectionType) [with Func1 = void (DeviceDiscoveryDialog::*)(const QString&); Func2 = void (MainWindow_BT::*)(const QString&)]':
                              ../CAT_BT/device.cpp:121:49:   required from here
                              /usr/include/x86_64-linux-gnu/qt5/QtCore/qobject.h:293:13: error: invalid use of incomplete type 'struct QtPrivate::QEnableIf<false, QMetaObject::Connection>'
                              In file included from /usr/include/x86_64-linux-gnu/qt5/QtCore/qatomic.h:34:0,
                                               from /usr/include/x86_64-linux-gnu/qt5/QtCore/qvariant.h:37,
                                               from /usr/include/x86_64-linux-gnu/qt5/QtCore/QVariant:1,
                                               from .uic/ui_device.h:12,
                                               from ../CAT_BT/device.h:56,
                                               from ../CAT_BT/device.cpp:51:
                              /usr/include/x86_64-linux-gnu/qt5/QtCore/qglobal.h:1073:45: note: declaration of 'struct QtPrivate::QEnableIf<false, QMetaObject::Connection>'
                               template <bool B, typename T = void> struct QEnableIf;
                                                                           ^
                              ../CAT_BT/device.cpp: In member function 'void DeviceDiscoveryDialog::displayPairingMenu(const QPoint&)':
                              ../CAT_BT/device.cpp:409:14: warning: unused variable 'testAction' [-Wunused-variable]
                                   QAction *testAction = menu.addAction("BT test menu add... ");
                                            ^
                              ../CAT_BT/device.cpp: At global scope:
                              ../CAT_BT/device.cpp:461:47: warning: unused parameter 'message' [-Wunused-parameter]
                               int DeviceDiscoveryDialog::StatusBar(QString *message)
                                                                             ^
                              Makefile:606: recipe for target '.obj/device.o' failed
                              make: *** [.obj/device.o] Error 1
                              19:21:42: The process "/usr/bin/make" exited with code 2.
                              Error while building/deploying project CAT_BT (kit: Desktop)
                              When executing step "Make"
                              
                              JonBJ 1 Reply Last reply 9 Sept 2020, 08:19
                              0
                              • C Offline
                                C Offline
                                Chris Kawa
                                Lifetime Qt Champion
                                wrote on 9 Sept 2020, 08:08 last edited by
                                #31

                                In the connect statement third param is a pointer to object and fourth is a member of that object class.

                                You're in DeviceDiscoveryDialog constructor so this is of class DeviceDiscoveryDialog. In your connect you have a member of MainWindow_BT. This can't work. You can't call a method of class A on an instance of class B.
                                If you use this as third parameter the fourth needs to be a member of its class, so &DeviceDiscovery::SomethingSomething.
                                If you want the fourth parameter to be &MainWindow_BT::displayStatusMessage the third parameter needs to be a pointer to an instance of that class.

                                As @SGaist already mentioned - you probably don't have a pointer to MainWindow_BT in your DeviceDiscoveryDialog class. You're doing the connect in the wrong place. If you're creating an instance of DeviceDiscoveryDialog in MainWindow_BT then you should do that connect in MainWindow_BT, where you have both pointers available, not in the dialog that does not have access to the instance that created it.

                                A 1 Reply Last reply 9 Sept 2020, 14:30
                                4
                                • A Anonymous_Banned275
                                  9 Sept 2020, 00:52

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

                                  Equals this:
                                  connect(test, &TestWidget::someSignal, this, &MainWindow::randomFnctn);

                                  Please note - I may be repeating my errors but I do not post just to get "cut and paste" confirmations of my posts.
                                  I am hoping somebody will help find / lead me to a solution.
                                  .

                                  Here is a faulty - need of solution - code snippet .

                                  DeviceDiscoveryDialog::DeviceDiscoveryDialog(QWidget *parent)
                                      :   QDialog(parent), localDevice(new QBluetoothLocalDevice),
                                        ui(new Ui_DeviceDiscovery)
                                  {
                                     ui->setupUi(this);
                                     discoveryAgent = new QBluetoothDeviceDiscoveryAgent();
                                  // working connect 
                                      connect(ui->scan, SIGNAL(clicked()), this, SLOT(startScan()));
                                  // faulty connect 
                                  both sendStatus and displayStatusMessage are given/ completed by intellisnese - they exists,  and are valid BUT 
                                  this code throws  an error 
                                      connect(ui->scan,
                                              &DeviceDiscoveryDialog::sendStatus,
                                              this,
                                              &MainWindow_BT::displayStatusMessage);
                                  

                                  **Compiler output AFTERT "no matching function" error

                                  &MainWindow_BT::displayStatusMessage);
                                  

                                  is declared**

                                  This is just " connect" error, I have NOT implemented the actual "emit" to use it. Not until it passes by complier.

                                  ../CAT_BT/device.cpp: In constructor 'DeviceDiscoveryDialog::DeviceDiscoveryDialog(QWidget*)':
                                  ../CAT_BT/device.cpp:121:49: error: no matching function for call to 'DeviceDiscoveryDialog::connect(QPushButton*&, void (DeviceDiscoveryDialog::*)(const QString&), DeviceDiscoveryDialog*, void (MainWindow_BT::*)(const QString&))'
                                               &MainWindow_BT::displayStatusMessage);
                                                                                   ^
                                  In file included from /usr/include/x86_64-linux-gnu/qt5/QtCore/qvariant.h:45:0,
                                                   from /usr/include/x86_64-linux-gnu/qt5/QtCore/QVariant:1,
                                                   from .uic/ui_device.h:12,
                                                   from ../CAT_BT/device.h:56,
                                                   from ../CAT_BT/device.cpp:51:
                                  /usr/include/x86_64-linux-gnu/qt5/QtCore/qobject.h:196:36: note: candidate: static QMetaObject::Connection QObject::connect(const QObject*, const char*, const QObject*, const char*, Qt::ConnectionType)
                                       static QMetaObject::Connection connect(const QObject *sender, const char *signal,
                                                                      ^
                                  /usr/include/x86_64-linux-gnu/qt5/QtCore/qobject.h:196:36: note:   no known conversion for argument 2 from 'void (DeviceDiscoveryDialog::*)(const QString&)' to 'const char*'
                                  /usr/include/x86_64-linux-gnu/qt5/QtCore/qobject.h:199:36: note: candidate: static QMetaObject::Connection QObject::connect(const QObject*, const QMetaMethod&, const QObject*, const QMetaMethod&, Qt::ConnectionType)
                                       static QMetaObject::Connection connect(const QObject *sender, const QMetaMethod &signal,
                                                                      ^
                                  /usr/include/x86_64-linux-gnu/qt5/QtCore/qobject.h:199:36: note:   no known conversion for argument 2 from 'void (DeviceDiscoveryDialog::*)(const QString&)' to 'const QMetaMethod&'
                                  /usr/include/x86_64-linux-gnu/qt5/QtCore/qobject.h:475:32: note: candidate: QMetaObject::Connection QObject::connect(const QObject*, const char*, const char*, Qt::ConnectionType) const
                                   inline QMetaObject::Connection QObject::connect(const QObject *asender, const char *asignal,
                                                                  ^
                                  /usr/include/x86_64-linux-gnu/qt5/QtCore/qobject.h:475:32: note:   no known conversion for argument 2 from 'void (DeviceDiscoveryDialog::*)(const QString&)' to 'const char*'
                                  /usr/include/x86_64-linux-gnu/qt5/QtCore/qobject.h:213:43: note: candidate: static QMetaObject::Connection QObject::connect(const typename QtPrivate::FunctionPointer<Func>::Object*, Func1, const typename QtPrivate::FunctionPointer<Func2>::Object*, Func2, Qt::ConnectionType) [with Func1 = void (DeviceDiscoveryDialog::*)(const QString&); Func2 = void (MainWindow_BT::*)(const QString&); typename QtPrivate::FunctionPointer<Func>::Object = DeviceDiscoveryDialog; typename QtPrivate::FunctionPointer<Func2>::Object = MainWindow_BT]
                                       static inline QMetaObject::Connection connect(const typename QtPrivate::FunctionPointer<Func1>::Object *sender, Func1 signal,
                                                                             ^
                                  /usr/include/x86_64-linux-gnu/qt5/QtCore/qobject.h:213:43: note:   no known conversion for argument 1 from 'QPushButton*' to 'const Object* {aka const DeviceDiscoveryDialog*}'
                                  /usr/include/x86_64-linux-gnu/qt5/QtCore/qobject.h:245:13: note: candidate: template<class Func1, class Func2> static typename QtPrivate::QEnableIf<((int)(QtPrivate::FunctionPointer<Func2>::ArgumentCount) >= 0), QMetaObject::Connection>::Type QObject::connect(const typename QtPrivate::FunctionPointer<Func>::Object*, Func1, Func2)
                                               connect(const typename QtPrivate::FunctionPointer<Func1>::Object *sender, Func1 signal, Func2 slot)
                                               ^
                                  /usr/include/x86_64-linux-gnu/qt5/QtCore/qobject.h:245:13: note:   template argument deduction/substitution failed:
                                  ../CAT_BT/device.cpp:121:49: note:   candidate expects 3 arguments, 4 provided
                                               &MainWindow_BT::displayStatusMessage);
                                                                                   ^
                                  In file included from /usr/include/x86_64-linux-gnu/qt5/QtCore/qvariant.h:45:0,
                                                   from /usr/include/x86_64-linux-gnu/qt5/QtCore/QVariant:1,
                                                   from .uic/ui_device.h:12,
                                                   from ../CAT_BT/device.h:56,
                                                   from ../CAT_BT/device.cpp:51:
                                  /usr/include/x86_64-linux-gnu/qt5/QtCore/qobject.h:254:13: note: candidate: template<class Func1, class Func2> static typename QtPrivate::QEnableIf<(((int)(QtPrivate::FunctionPointer<Func2>::ArgumentCount) >= 0) && (! QtPrivate::FunctionPointer<Func2>::IsPointerToMemberFunction)), QMetaObject::Connection>::Type QObject::connect(const typename QtPrivate::FunctionPointer<Func>::Object*, Func1, const QObject*, Func2, Qt::ConnectionType)
                                               connect(const typename QtPrivate::FunctionPointer<Func1>::Object *sender, Func1 signal, const QObject *context, Func2 slot,
                                               ^
                                  /usr/include/x86_64-linux-gnu/qt5/QtCore/qobject.h:254:13: note:   template argument deduction/substitution failed:
                                  /usr/include/x86_64-linux-gnu/qt5/QtCore/qobject.h: In substitution of 'template<class Func1, class Func2> static typename QtPrivate::QEnableIf<(((int)(QtPrivate::FunctionPointer<Func2>::ArgumentCount) >= 0) && (! QtPrivate::FunctionPointer<Func2>::IsPointerToMemberFunction)), QMetaObject::Connection>::Type QObject::connect(const typename QtPrivate::FunctionPointer<Func>::Object*, Func1, const QObject*, Func2, Qt::ConnectionType) [with Func1 = void (DeviceDiscoveryDialog::*)(const QString&); Func2 = void (MainWindow_BT::*)(const QString&)]':
                                  ../CAT_BT/device.cpp:121:49:   required from here
                                  /usr/include/x86_64-linux-gnu/qt5/QtCore/qobject.h:254:13: error: invalid use of incomplete type 'struct QtPrivate::QEnableIf<false, QMetaObject::Connection>'
                                  In file included from /usr/include/x86_64-linux-gnu/qt5/QtCore/qatomic.h:34:0,
                                                   from /usr/include/x86_64-linux-gnu/qt5/QtCore/qvariant.h:37,
                                                   from /usr/include/x86_64-linux-gnu/qt5/QtCore/QVariant:1,
                                                   from .uic/ui_device.h:12,
                                                   from ../CAT_BT/device.h:56,
                                                   from ../CAT_BT/device.cpp:51:
                                  /usr/include/x86_64-linux-gnu/qt5/QtCore/qglobal.h:1073:45: note: declaration of 'struct QtPrivate::QEnableIf<false, QMetaObject::Connection>'
                                   template <bool B, typename T = void> struct QEnableIf;
                                                                               ^
                                  In file included from /usr/include/x86_64-linux-gnu/qt5/QtCore/qvariant.h:45:0,
                                                   from /usr/include/x86_64-linux-gnu/qt5/QtCore/QVariant:1,
                                                   from .uic/ui_device.h:12,
                                                   from ../CAT_BT/device.h:56,
                                                   from ../CAT_BT/device.cpp:51:
                                  /usr/include/x86_64-linux-gnu/qt5/QtCore/qobject.h:285:13: note: candidate: template<class Func1, class Func2> static typename QtPrivate::QEnableIf<(QtPrivate::FunctionPointer<Func2>::ArgumentCount == (-1)), QMetaObject::Connection>::Type QObject::connect(const typename QtPrivate::FunctionPointer<Func>::Object*, Func1, Func2)
                                               connect(const typename QtPrivate::FunctionPointer<Func1>::Object *sender, Func1 signal, Func2 slot)
                                               ^
                                  /usr/include/x86_64-linux-gnu/qt5/QtCore/qobject.h:285:13: note:   template argument deduction/substitution failed:
                                  ../CAT_BT/device.cpp:121:49: note:   candidate expects 3 arguments, 4 provided
                                               &MainWindow_BT::displayStatusMessage);
                                                                                   ^
                                  In file included from /usr/include/x86_64-linux-gnu/qt5/QtCore/qvariant.h:45:0,
                                                   from /usr/include/x86_64-linux-gnu/qt5/QtCore/QVariant:1,
                                                   from .uic/ui_device.h:12,
                                                   from ../CAT_BT/device.h:56,
                                                   from ../CAT_BT/device.cpp:51:
                                  /usr/include/x86_64-linux-gnu/qt5/QtCore/qobject.h:293:13: note: candidate: template<class Func1, class Func2> static typename QtPrivate::QEnableIf<(QtPrivate::FunctionPointer<Func2>::ArgumentCount == (-1)), QMetaObject::Connection>::Type QObject::connect(const typename QtPrivate::FunctionPointer<Func>::Object*, Func1, const QObject*, Func2, Qt::ConnectionType)
                                               connect(const typename QtPrivate::FunctionPointer<Func1>::Object *sender, Func1 signal, const QObject *context, Func2 slot,
                                               ^
                                  /usr/include/x86_64-linux-gnu/qt5/QtCore/qobject.h:293:13: note:   template argument deduction/substitution failed:
                                  /usr/include/x86_64-linux-gnu/qt5/QtCore/qobject.h: In substitution of 'template<class Func1, class Func2> static typename QtPrivate::QEnableIf<(QtPrivate::FunctionPointer<Func2>::ArgumentCount == (-1)), QMetaObject::Connection>::Type QObject::connect(const typename QtPrivate::FunctionPointer<Func>::Object*, Func1, const QObject*, Func2, Qt::ConnectionType) [with Func1 = void (DeviceDiscoveryDialog::*)(const QString&); Func2 = void (MainWindow_BT::*)(const QString&)]':
                                  ../CAT_BT/device.cpp:121:49:   required from here
                                  /usr/include/x86_64-linux-gnu/qt5/QtCore/qobject.h:293:13: error: invalid use of incomplete type 'struct QtPrivate::QEnableIf<false, QMetaObject::Connection>'
                                  In file included from /usr/include/x86_64-linux-gnu/qt5/QtCore/qatomic.h:34:0,
                                                   from /usr/include/x86_64-linux-gnu/qt5/QtCore/qvariant.h:37,
                                                   from /usr/include/x86_64-linux-gnu/qt5/QtCore/QVariant:1,
                                                   from .uic/ui_device.h:12,
                                                   from ../CAT_BT/device.h:56,
                                                   from ../CAT_BT/device.cpp:51:
                                  /usr/include/x86_64-linux-gnu/qt5/QtCore/qglobal.h:1073:45: note: declaration of 'struct QtPrivate::QEnableIf<false, QMetaObject::Connection>'
                                   template <bool B, typename T = void> struct QEnableIf;
                                                                               ^
                                  ../CAT_BT/device.cpp: In member function 'void DeviceDiscoveryDialog::displayPairingMenu(const QPoint&)':
                                  ../CAT_BT/device.cpp:409:14: warning: unused variable 'testAction' [-Wunused-variable]
                                       QAction *testAction = menu.addAction("BT test menu add... ");
                                                ^
                                  ../CAT_BT/device.cpp: At global scope:
                                  ../CAT_BT/device.cpp:461:47: warning: unused parameter 'message' [-Wunused-parameter]
                                   int DeviceDiscoveryDialog::StatusBar(QString *message)
                                                                                 ^
                                  Makefile:606: recipe for target '.obj/device.o' failed
                                  make: *** [.obj/device.o] Error 1
                                  19:21:42: The process "/usr/bin/make" exited with code 2.
                                  Error while building/deploying project CAT_BT (kit: Desktop)
                                  When executing step "Make"
                                  
                                  JonBJ Offline
                                  JonBJ Offline
                                  JonB
                                  wrote on 9 Sept 2020, 08:19 last edited by JonB 9 Sept 2020, 08:20
                                  #32

                                  @AnneRanch
                                  You need to act on the final paragraph of @Chris-Kawa's answer and @SGaist's comment, for the error to go away.

                                  A 1 Reply Last reply 9 Sept 2020, 14:41
                                  0
                                  • C Chris Kawa
                                    9 Sept 2020, 08:08

                                    In the connect statement third param is a pointer to object and fourth is a member of that object class.

                                    You're in DeviceDiscoveryDialog constructor so this is of class DeviceDiscoveryDialog. In your connect you have a member of MainWindow_BT. This can't work. You can't call a method of class A on an instance of class B.
                                    If you use this as third parameter the fourth needs to be a member of its class, so &DeviceDiscovery::SomethingSomething.
                                    If you want the fourth parameter to be &MainWindow_BT::displayStatusMessage the third parameter needs to be a pointer to an instance of that class.

                                    As @SGaist already mentioned - you probably don't have a pointer to MainWindow_BT in your DeviceDiscoveryDialog class. You're doing the connect in the wrong place. If you're creating an instance of DeviceDiscoveryDialog in MainWindow_BT then you should do that connect in MainWindow_BT, where you have both pointers available, not in the dialog that does not have access to the instance that created it.

                                    A Offline
                                    A Offline
                                    Anonymous_Banned275
                                    wrote on 9 Sept 2020, 14:30 last edited by
                                    #33

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

                                    In the connect statement third param is a pointer to object and fourth is a member of that object class.

                                    You're in DeviceDiscoveryDialog constructor so this is of class DeviceDiscoveryDialog. In your connect you have a member of MainWindow_BT. This can't work. You can't call a method of class A on an instance of class B.
                                    If you use this as third parameter the fourth needs to be a member of its class, so &DeviceDiscovery::SomethingSomething.
                                    If you want the fourth parameter to be &MainWindow_BT::displayStatusMessage the third parameter needs to be a pointer to an instance of that class.

                                    As @SGaist already mentioned - you probably don't have a pointer to MainWindow_BT in your DeviceDiscoveryDialog class. You're doing the connect in the wrong place. If you're creating an instance of DeviceDiscoveryDialog in MainWindow_BT then you should do that connect in MainWindow_BT, where you have both pointers available, not in the dialog that does not have access to the instance that created it.

                                    Thanks Cris,
                                    as always you are right on the money with your explanation.

                                    Now for absolutely last question in this discussion -
                                    why does intelisense offers inaccessible pointer as a valid entry ?

                                    Moral of the story - use intellisense with caution and NOT as a replacement for my albeit limited " experience / intelligence" .

                                    1 Reply Last reply
                                    0
                                    • JonBJ JonB
                                      9 Sept 2020, 08:19

                                      @AnneRanch
                                      You need to act on the final paragraph of @Chris-Kawa's answer and @SGaist's comment, for the error to go away.

                                      A Offline
                                      A Offline
                                      Anonymous_Banned275
                                      wrote on 9 Sept 2020, 14:41 last edited by
                                      #34
                                      This post is deleted!
                                      JonBJ 1 Reply Last reply 9 Sept 2020, 14:54
                                      -1
                                      • A Anonymous_Banned275
                                        9 Sept 2020, 14:41

                                        This post is deleted!

                                        JonBJ Offline
                                        JonBJ Offline
                                        JonB
                                        wrote on 9 Sept 2020, 14:54 last edited by JonB 9 Sept 2020, 14:57
                                        #35
                                        This post is deleted!
                                        A 1 Reply Last reply 9 Sept 2020, 16:12
                                        1
                                        • JonBJ JonB
                                          9 Sept 2020, 14:54

                                          This post is deleted!

                                          A Offline
                                          A Offline
                                          Anonymous_Banned275
                                          wrote on 9 Sept 2020, 16:12 last edited by
                                          #36

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

                                          @AnneRanch
                                          You are beyond rude (and not for the first time). I was trying to draw your attention to the fact that you will not solve your error message until you move where you are trying to do the connect(), rather than playing with its parameters where it currently is. I was short, polite & helpful.

                                          It's nice to know when @Chris-Kawa tells you this in hist last paragraph, you find it helpful. When I merely tried to draw your attention to the last of his paragraphs --- which is what you need to act on before you worry about understanding the preceding stuff --- his is helpful, mine is "superficial" and "does not help solve" and "inappropriate" and seems to demand an apology from you.

                                          Why is my comment "inappropriate"? Where have I ever asked you to apologise or say sorry for anything?

                                          Just unbelievable. GtH.

                                          Beyond rude post deleted .

                                          1 Reply Last reply
                                          0

                                          26/37

                                          7 Sept 2020, 17:24

                                          • Login

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