Combining classes - append class to QMainWindow
-
@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.
-
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.
@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 acceptsQString
, 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);
-
@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"
-
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 sothis
is of classDeviceDiscoveryDialog
. In your connect you have a member ofMainWindow_BT
. This can't work. You can't call a method of class A on an instance of class B.
If you usethis
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 yourDeviceDiscoveryDialog
class. You're doing the connect in the wrong place. If you're creating an instance ofDeviceDiscoveryDialog
inMainWindow_BT
then you should do that connect inMainWindow_BT
, where you have both pointers available, not in the dialog that does not have access to the instance that created it. -
@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"
-
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 sothis
is of classDeviceDiscoveryDialog
. In your connect you have a member ofMainWindow_BT
. This can't work. You can't call a method of class A on an instance of class B.
If you usethis
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 yourDeviceDiscoveryDialog
class. You're doing the connect in the wrong place. If you're creating an instance ofDeviceDiscoveryDialog
inMainWindow_BT
then you should do that connect inMainWindow_BT
, where you have both pointers available, not in the dialog that does not have access to the instance that created it.@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 sothis
is of classDeviceDiscoveryDialog
. In your connect you have a member ofMainWindow_BT
. This can't work. You can't call a method of class A on an instance of class B.
If you usethis
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 yourDeviceDiscoveryDialog
class. You're doing the connect in the wrong place. If you're creating an instance ofDeviceDiscoveryDialog
inMainWindow_BT
then you should do that connect inMainWindow_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" .
-
@AnneRanch
You need to act on the final paragraph of @Chris-Kawa's answer and @SGaist's comment, for the error to go away.This post is deleted! -
This post is deleted!
-
@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 theconnect()
, 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 .
-
Keep your cool everyone. The world is messed up as it is. Lets try to stay positive and friendly at least here ;)
Anywho...
why does intelisense offers inaccessible pointer as a valid entry ?
It's a best guess effort. C++ is complicated language to provide accurate suggestions without actually compiling the whole thing. In some cases it doesn't have enough context so it uses heuristics to merely suggest what a valid syntax for given expression is without much consideration for the actual correctness of the program as a whole. Code completion is usually a lot more accurate in managed languages like C# or Java, as you have full language reflection at your disposal. In C++ a simple thing like
#define true false
can wreak havoc on suggestions.I'd suggest to treat code completion as a basic name and syntax helper. Sometimes you don't remember exact function or parameter name. Sometimes the param list is just long and it helps you save a few key strokes to type it in. Sometimes you want to quickly browse through class members looking for familiar keyword. For those cases it works well enough. I wouldn't rely on it to suggest meaningful code logic though. That should be on the programmer anyway IMO. In case of
connect
's it's especially important to understand what relations you're creating so relying on machine suggestions is not a good idea, at least until we have that world class AI made :P