I am making a QT application. I have a MainWindow1
class and a FirstTab
class. The MainWindow1
class is a QMainWindow
and inside I created this signal ->
mainwindow1.h
signals:
void loadDateSig(QString strDate);
And in FirstTab
I created this slot->
FirstTab.h
public slots:
void loadDate(QString date);
Q_Object
is defined in both MainWindow1
and in FirstTab
. Now in my MainWindow1
constructor, this is how I start ->
mainwindow1.cpp
MainWindow1::MainWindow1()
: mainWidget(new QTabWidget) {
setCentralWidget(mainWidget);
mainWidget->addTab(new FirstTab(mainWidget), "First");
createActions();
createStatusBar();
And below that, I start making some connections. I connect a few items to change the status that the document was modified. You can see them here, and these work with no issues ->
connect(mainWidget->findChild<QTimeEdit *>("timeEdit"), &QTimeEdit::editingFinished,
this, &MainWindow1::documentWasModified);
connect(mainWidget->findChild<QDateEdit *>("dateEdit"), &QTimeEdit::editingFinished,
this, &MainWindow1::documentWasModified);
connect(mainWidget->findChild<QLineEdit *>("shooterEdit"), &QLineEdit::textEdited,
this, &MainWindow1::documentWasModified);
connect(mainWidget->findChild<QLineEdit *>("recorderEdit"), &QLineEdit::textEdited,
this, &MainWindow1::documentWasModified);
connect(mainWidget->findChild<QDoubleSpinBox *>("tempCSpin"), &QDoubleSpinBox::editingFinished,
this, &MainWindow1::documentWasModified);
connect(mainWidget->findChild<QDoubleSpinBox *>("tempFSpin"), &QDoubleSpinBox::editingFinished,
this, &MainWindow1::documentWasModified);
Now I try to connect my loadDateSig
and loadDate
. I have tried both creating the connect in the child, and in the parent class. But both give me an error. I tried to connect similar to how I connected previosly ->
connect(this, &MainWindow1::loadDateSig, mainWidget->findChild<QWidget *>("tab1"), &FirstTab::loadDate);
However, this doesn't seem to work. I get these errors ->
====================[ Build | all | Debug ]=====================================
"E:\Program Files (x86)\CLion 2022.2.1\bin\cmake\win\bin\cmake.exe" --build E:\Projects\Galvion\cmake-build-debug --target all -j 9
[1/4] Automatic MOC and UIC for target Galvion
[2/3] Building CXX object CMakeFiles/Galvion.dir/mainwindow1.cpp.obj
FAILED: CMakeFiles/Galvion.dir/mainwindow1.cpp.obj
E:\PROGRA~1\CLION2~1.1\bin\mingw\bin\G__~1.EXE -DMINGW_HAS_SECURE_API=1 -DQT_CORE_LIB -DQT_GUI_LIB -DQT_WIDGETS_LIB -DUNICODE -DWIN32 -DWIN64 -D_ENABLE_EXTENDED_ALIGNED_STORAGE -D_UNICODE -D_WIN64 -IE:/Projects/Galvion/cmake-build-debug -IE:/Projects/Galvion -IE:/Projects/Galvion/cmake-build-debug/Galvion_autogen/include -isystem C:/Qt/6.4.1/mingw_64/include/QtCore -isystem C:/Qt/6.4.1/mingw_64/include -isystem C:/Qt/6.4.1/mingw_64/mkspecs/win32-g++ -isystem C:/Qt/6.4.1/mingw_64/include/QtGui -isystem C:/Qt/6.4.1/mingw_64/include/QtWidgets -g -MD -MT CMakeFiles/Galvion.dir/mainwindow1.cpp.obj -MF CMakeFiles\Galvion.dir\mainwindow1.cpp.obj.d -o CMakeFiles/Galvion.dir/mainwindow1.cpp.obj -c E:/Projects/Galvion/mainwindow1.cpp
E:/Projects/Galvion/mainwindow1.cpp: In constructor 'MainWindow1::MainWindow1()':
E:/Projects/Galvion/mainwindow1.cpp:26:12: error: no matching function for call to 'MainWindow1::connect(MainWindow1*, void (MainWindow1::*)(QString), QWidget*, void (FirstTab::*)(QString))'
26 | connect(this, &MainWindow1::loadDateSig, mainWidget->findChild<QWidget *>("tab1"), &FirstTab::loadDate);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from C:/Qt/6.4.1/mingw_64/include/QtCore/qabstractanimation.h:7,
from C:/Qt/6.4.1/mingw_64/include/QtCore/QtCore:10,
from C:/Qt/6.4.1/mingw_64/include/QtWidgets/QtWidgetsDepends:3,
from C:/Qt/6.4.1/mingw_64/include/QtWidgets/QTWidgets:3,
from E:/Projects/Galvion/mainwindow1.h:7,
from E:/Projects/Galvion/mainwindow1.cpp:1:
C:/Qt/6.4.1/mingw_64/include/QtCore/qobject.h:201: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 (MainWindow1::*)(QString); Func2 = void (FirstTab::*)(QString); typename QtPrivate::FunctionPointer<Func>::Object = MainWindow1; typename QtPrivate::FunctionPointer<Func2>::Object = FirstTab]' (near match)
201 | static inline QMetaObject::Connection connect(const typename QtPrivate::FunctionPointer<Func1>::Object *sender, Func1 signal,
| ^~~~~~~
C:/Qt/6.4.1/mingw_64/include/QtCore/qobject.h:201:43: note: conversion of argument 3 would be ill-formed:
E:/Projects/Galvion/mainwindow1.cpp:26:78: error: invalid conversion from 'QWidget*' to 'const Object*' {aka 'const FirstTab*'} [-fpermissive]
26 | connect(this, &MainWindow1::loadDateSig, mainWidget->findChild<QWidget *>("tab1"), &FirstTab::loadDate);
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~
| |
| QWidget*
In file included from C:/Qt/6.4.1/mingw_64/include/QtCore/qabstractanimation.h:7,
from C:/Qt/6.4.1/mingw_64/include/QtCore/QtCore:10,
from C:/Qt/6.4.1/mingw_64/include/QtWidgets/QtWidgetsDepends:3,
from C:/Qt/6.4.1/mingw_64/include/QtWidgets/QTWidgets:3,
from E:/Projects/Galvion/mainwindow1.h:7,
from E:/Projects/Galvion/mainwindow1.cpp:1:
C:/Qt/6.4.1/mingw_64/include/QtCore/qobject.h:233:13: note: candidate: 'template<class Func1, class Func2> static typename std::enable_if<((int)(QtPrivate::FunctionPointer<Func2>::ArgumentCount) >= 0), QMetaObject::Connection>::type QObject::connect(const typename QtPrivate::FunctionPointer<Func>::Object*, Func1, Func2)'
233 | connect(const typename QtPrivate::FunctionPointer<Func1>::Object *sender, Func1 signal, Func2 slot)
| ^~~~~~~
C:/Qt/6.4.1/mingw_64/include/QtCore/qobject.h:233:13: note: template argument deduction/substitution failed:
E:/Projects/Galvion/mainwindow1.cpp:26:12: note: candidate expects 3 arguments, 4 provided
26 | connect(this, &MainWindow1::loadDateSig, mainWidget->findChild<QWidget *>("tab1"), &FirstTab::loadDate);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from C:/Qt/6.4.1/mingw_64/include/QtCore/qabstractanimation.h:7,
from C:/Qt/6.4.1/mingw_64/include/QtCore/QtCore:10,
from C:/Qt/6.4.1/mingw_64/include/QtWidgets/QtWidgetsDepends:3,
from C:/Qt/6.4.1/mingw_64/include/QtWidgets/QTWidgets:3,
from E:/Projects/Galvion/mainwindow1.h:7,
from E:/Projects/Galvion/mainwindow1.cpp:1:
C:/Qt/6.4.1/mingw_64/include/QtCore/qobject.h:242:13: note: candidate: 'template<class Func1, class Func2> static typename std::enable_if<(((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)'
242 | connect(const typename QtPrivate::FunctionPointer<Func1>::Object *sender, Func1 signal, const QObject *context, Func2 slot,
| ^~~~~~~
C:/Qt/6.4.1/mingw_64/include/QtCore/qobject.h:242:13: note: template argument deduction/substitution failed:
C:/Qt/6.4.1/mingw_64/include/QtCore/qobject.h: In substitution of 'template<class Func1, class Func2> static typename std::enable_if<(((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 (MainWindow1::*)(QString); Func2 = void (FirstTab::*)(QString)]':
E:/Projects/Galvion/mainwindow1.cpp:26:12: required from here
C:/Qt/6.4.1/mingw_64/include/QtCore/qobject.h:242:13: error: no type named 'type' in 'struct std::enable_if<false, QMetaObject::Connection>'
C:/Qt/6.4.1/mingw_64/include/QtCore/qobject.h:276:13: note: candidate: 'template<class Func1, class Func2> static typename std::enable_if<((QtPrivate::FunctionPointer<Func2>::ArgumentCount == -1) && (! is_convertible_v<Func2, const char*>)), QMetaObject::Connection>::type QObject::connect(const typename QtPrivate::FunctionPointer<Func>::Object*, Func1, Func2)'
276 | connect(const typename QtPrivate::FunctionPointer<Func1>::Object *sender, Func1 signal, Func2 slot)
| ^~~~~~~
C:/Qt/6.4.1/mingw_64/include/QtCore/qobject.h:276:13: note: template argument deduction/substitution failed:
E:/Projects/Galvion/mainwindow1.cpp:26:12: note: candidate expects 3 arguments, 4 provided
26 | connect(this, &MainWindow1::loadDateSig, mainWidget->findChild<QWidget *>("tab1"), &FirstTab::loadDate);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from C:/Qt/6.4.1/mingw_64/include/QtCore/qabstractanimation.h:7,
from C:/Qt/6.4.1/mingw_64/include/QtCore/QtCore:10,
from C:/Qt/6.4.1/mingw_64/include/QtWidgets/QtWidgetsDepends:3,
from C:/Qt/6.4.1/mingw_64/include/QtWidgets/QTWidgets:3,
from E:/Projects/Galvion/mainwindow1.h:7,
from E:/Projects/Galvion/mainwindow1.cpp:1:
C:/Qt/6.4.1/mingw_64/include/QtCore/qobject.h:287:13: note: candidate: 'template<class Func1, class Func2> static typename std::enable_if<((QtPrivate::FunctionPointer<Func2>::ArgumentCount == -1) && (! is_convertible_v<Func2, const char*>)), QMetaObject::Connection>::type QObject::connect(const typename QtPrivate::FunctionPointer<Func>::Object*, Func1, const QObject*, Func2, Qt::ConnectionType)'
287 | connect(const typename QtPrivate::FunctionPointer<Func1>::Object *sender, Func1 signal, const QObject *context, Func2 slot,
| ^~~~~~~
C:/Qt/6.4.1/mingw_64/include/QtCore/qobject.h:287:13: note: template argument deduction/substitution failed:
C:/Qt/6.4.1/mingw_64/include/QtCore/qobject.h: In substitution of 'template<class Func1, class Func2> static typename std::enable_if<((QtPrivate::FunctionPointer<Func2>::ArgumentCount == -1) && (! is_convertible_v<Func2, const char*>)), QMetaObject::Connection>::type QObject::connect(const typename QtPrivate::FunctionPointer<Func>::Object*, Func1, const QObject*, Func2, Qt::ConnectionType) [with Func1 = void (MainWindow1::*)(QString); Func2 = void (FirstTab::*)(QString)]':
E:/Projects/Galvion/mainwindow1.cpp:26:12: required from here
C:/Qt/6.4.1/mingw_64/include/QtCore/qobject.h:287:13: error: no type named 'type' in 'struct std::enable_if<false, QMetaObject::Connection>'
C:/Qt/6.4.1/mingw_64/include/QtCore/qobject.h:181:36: note: candidate: 'static QMetaObject::Connection QObject::connect(const QObject*, const char*, const QObject*, const char*, Qt::ConnectionType)'
181 | static QMetaObject::Connection connect(const QObject *sender, const char *signal,
| ^~~~~~~
C:/Qt/6.4.1/mingw_64/include/QtCore/qobject.h:181:79: note: no known conversion for argument 2 from 'void (MainWindow1::*)(QString)' to 'const char*'
181 | static QMetaObject::Connection connect(const QObject *sender, const char *signal,
| ~~~~~~~~~~~~^~~~~~
C:/Qt/6.4.1/mingw_64/include/QtCore/qobject.h:184:36: note: candidate: 'static QMetaObject::Connection QObject::connect(const QObject*, const QMetaMethod&, const QObject*, const QMetaMethod&, Qt::ConnectionType)'
184 | static QMetaObject::Connection connect(const QObject *sender, const QMetaMethod &signal,
| ^~~~~~~
C:/Qt/6.4.1/mingw_64/include/QtCore/qobject.h:184:86: note: no known conversion for argument 2 from 'void (MainWindow1::*)(QString)' to 'const QMetaMethod&'
184 | static QMetaObject::Connection connect(const QObject *sender, const QMetaMethod &signal,
| ~~~~~~~~~~~~~~~~~~~^~~~~~
C:/Qt/6.4.1/mingw_64/include/QtCore/qobject.h:432:32: note: candidate: 'QMetaObject::Connection QObject::connect(const QObject*, const char*, const char*, Qt::ConnectionType) const'
432 | inline QMetaObject::Connection QObject::connect(const QObject *asender, const char *asignal,
| ^~~~~~~
C:/Qt/6.4.1/mingw_64/include/QtCore/qobject.h:432:85: note: no known conversion for argument 2 from 'void (MainWindow1::*)(QString)' to 'const char*'
432 | inline QMetaObject::Connection QObject::connect(const QObject *asender, const char *asignal,
| ~~~~~~~~~~~~^~~~~~~
ninja: build stopped: subcommand failed.
Could anyone help me figure out why this happens?
I tried to create the connect in the FirstTab
class. Changing the parent in mainwindow1.cpp
form mainWidget
parent to this
so the child class can access the signal ->
mainWidget->addTab(new FirstTab(this), "First");
And then I create this connect in FirstTab.cpp
->
connect(parent, &MainWindow1::loadDateSig, this, &FirstTab::loadDate);
I get this error when trying to build ->
====================[ Build | all | Debug ]=====================================
"E:\Program Files (x86)\CLion 2022.2.1\bin\cmake\win\bin\cmake.exe" --build E:\Projects\Galvion\cmake-build-debug --target all -j 9
[1/5] Automatic MOC and UIC for target Galvion
[2/4] Building CXX object CMakeFiles/Galvion.dir/FirstTab.cpp.obj
FAILED: CMakeFiles/Galvion.dir/FirstTab.cpp.obj
E:\PROGRA~1\CLION2~1.1\bin\mingw\bin\G__~1.EXE -DMINGW_HAS_SECURE_API=1 -DQT_CORE_LIB -DQT_GUI_LIB -DQT_WIDGETS_LIB -DUNICODE -DWIN32 -DWIN64 -D_ENABLE_EXTENDED_ALIGNED_STORAGE -D_UNICODE -D_WIN64 -IE:/Projects/Galvion/cmake-build-debug -IE:/Projects/Galvion -IE:/Projects/Galvion/cmake-build-debug/Galvion_autogen/include -isystem C:/Qt/6.4.1/mingw_64/include/QtCore -isystem C:/Qt/6.4.1/mingw_64/include -isystem C:/Qt/6.4.1/mingw_64/mkspecs/win32-g++ -isystem C:/Qt/6.4.1/mingw_64/include/QtGui -isystem C:/Qt/6.4.1/mingw_64/include/QtWidgets -g -MD -MT CMakeFiles/Galvion.dir/FirstTab.cpp.obj -MF CMakeFiles\Galvion.dir\FirstTab.cpp.obj.d -o CMakeFiles/Galvion.dir/FirstTab.cpp.obj -c E:/Projects/Galvion/FirstTab.cpp
E:/Projects/Galvion/FirstTab.cpp: In constructor 'FirstTab::FirstTab(QWidget*)':
E:/Projects/Galvion/FirstTab.cpp:82:12: error: no matching function for call to 'FirstTab::connect(QWidget*&, void (MainWindow1::*)(QString), FirstTab*, void (FirstTab::*)(QString))'
82 | connect(parent, &MainWindow1::loadDateSig, this, &FirstTab::loadDate);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from C:/Qt/6.4.1/mingw_64/include/QtCore/qabstractanimation.h:7,
from C:/Qt/6.4.1/mingw_64/include/QtCore/QtCore:10,
from C:/Qt/6.4.1/mingw_64/include/QtWidgets/QtWidgetsDepends:3,
from C:/Qt/6.4.1/mingw_64/include/QtWidgets/QtWidgets:3,
from E:/Projects/Galvion/FirstTab.h:7,
from E:/Projects/Galvion/FirstTab.cpp:5:
C:/Qt/6.4.1/mingw_64/include/QtCore/qobject.h:201: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 (MainWindow1::*)(QString); Func2 = void (FirstTab::*)(QString); typename QtPrivate::FunctionPointer<Func>::Object = MainWindow1; typename QtPrivate::FunctionPointer<Func2>::Object = FirstTab]' (near match)
201 | static inline QMetaObject::Connection connect(const typename QtPrivate::FunctionPointer<Func1>::Object *sender, Func1 signal,
| ^~~~~~~
C:/Qt/6.4.1/mingw_64/include/QtCore/qobject.h:201:43: note: conversion of argument 1 would be ill-formed:
E:/Projects/Galvion/FirstTab.cpp:82:13: error: invalid conversion from 'QWidget*' to 'const Object*' {aka 'const MainWindow1*'} [-fpermissive]
82 | connect(parent, &MainWindow1::loadDateSig, this, &FirstTab::loadDate);
| ^~~~~~
| |
| QWidget*
In file included from C:/Qt/6.4.1/mingw_64/include/QtCore/qabstractanimation.h:7,
from C:/Qt/6.4.1/mingw_64/include/QtCore/QtCore:10,
from C:/Qt/6.4.1/mingw_64/include/QtWidgets/QtWidgetsDepends:3,
from C:/Qt/6.4.1/mingw_64/include/QtWidgets/QtWidgets:3,
from E:/Projects/Galvion/FirstTab.h:7,
from E:/Projects/Galvion/FirstTab.cpp:5:
C:/Qt/6.4.1/mingw_64/include/QtCore/qobject.h:233:13: note: candidate: 'template<class Func1, class Func2> static typename std::enable_if<((int)(QtPrivate::FunctionPointer<Func2>::ArgumentCount) >= 0), QMetaObject::Connection>::type QObject::connect(const typename QtPrivate::FunctionPointer<Func>::Object*, Func1, Func2)'
233 | connect(const typename QtPrivate::FunctionPointer<Func1>::Object *sender, Func1 signal, Func2 slot)
| ^~~~~~~
C:/Qt/6.4.1/mingw_64/include/QtCore/qobject.h:233:13: note: template argument deduction/substitution failed:
E:/Projects/Galvion/FirstTab.cpp:82:12: note: candidate expects 3 arguments, 4 provided
82 | connect(parent, &MainWindow1::loadDateSig, this, &FirstTab::loadDate);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from C:/Qt/6.4.1/mingw_64/include/QtCore/qabstractanimation.h:7,
from C:/Qt/6.4.1/mingw_64/include/QtCore/QtCore:10,
from C:/Qt/6.4.1/mingw_64/include/QtWidgets/QtWidgetsDepends:3,
from C:/Qt/6.4.1/mingw_64/include/QtWidgets/QtWidgets:3,
from E:/Projects/Galvion/FirstTab.h:7,
from E:/Projects/Galvion/FirstTab.cpp:5:
C:/Qt/6.4.1/mingw_64/include/QtCore/qobject.h:242:13: note: candidate: 'template<class Func1, class Func2> static typename std::enable_if<(((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)'
242 | connect(const typename QtPrivate::FunctionPointer<Func1>::Object *sender, Func1 signal, const QObject *context, Func2 slot,
| ^~~~~~~
C:/Qt/6.4.1/mingw_64/include/QtCore/qobject.h:242:13: note: template argument deduction/substitution failed:
C:/Qt/6.4.1/mingw_64/include/QtCore/qobject.h: In substitution of 'template<class Func1, class Func2> static typename std::enable_if<(((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 (MainWindow1::*)(QString); Func2 = void (FirstTab::*)(QString)]':
E:/Projects/Galvion/FirstTab.cpp:82:12: required from here
C:/Qt/6.4.1/mingw_64/include/QtCore/qobject.h:242:13: error: no type named 'type' in 'struct std::enable_if<false, QMetaObject::Connection>'
C:/Qt/6.4.1/mingw_64/include/QtCore/qobject.h:276:13: note: candidate: 'template<class Func1, class Func2> static typename std::enable_if<((QtPrivate::FunctionPointer<Func2>::ArgumentCount == -1) && (! is_convertible_v<Func2, const char*>)), QMetaObject::Connection>::type QObject::connect(const typename QtPrivate::FunctionPointer<Func>::Object*, Func1, Func2)'
276 | connect(const typename QtPrivate::FunctionPointer<Func1>::Object *sender, Func1 signal, Func2 slot)
| ^~~~~~~
C:/Qt/6.4.1/mingw_64/include/QtCore/qobject.h:276:13: note: template argument deduction/substitution failed:
E:/Projects/Galvion/FirstTab.cpp:82:12: note: candidate expects 3 arguments, 4 provided
82 | connect(parent, &MainWindow1::loadDateSig, this, &FirstTab::loadDate);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from C:/Qt/6.4.1/mingw_64/include/QtCore/qabstractanimation.h:7,
from C:/Qt/6.4.1/mingw_64/include/QtCore/QtCore:10,
from C:/Qt/6.4.1/mingw_64/include/QtWidgets/QtWidgetsDepends:3,
from C:/Qt/6.4.1/mingw_64/include/QtWidgets/QtWidgets:3,
from E:/Projects/Galvion/FirstTab.h:7,
from E:/Projects/Galvion/FirstTab.cpp:5:
C:/Qt/6.4.1/mingw_64/include/QtCore/qobject.h:287:13: note: candidate: 'template<class Func1, class Func2> static typename std::enable_if<((QtPrivate::FunctionPointer<Func2>::ArgumentCount == -1) && (! is_convertible_v<Func2, const char*>)), QMetaObject::Connection>::type QObject::connect(const typename QtPrivate::FunctionPointer<Func>::Object*, Func1, const QObject*, Func2, Qt::ConnectionType)'
287 | connect(const typename QtPrivate::FunctionPointer<Func1>::Object *sender, Func1 signal, const QObject *context, Func2 slot,
| ^~~~~~~
C:/Qt/6.4.1/mingw_64/include/QtCore/qobject.h:287:13: note: template argument deduction/substitution failed:
C:/Qt/6.4.1/mingw_64/include/QtCore/qobject.h: In substitution of 'template<class Func1, class Func2> static typename std::enable_if<((QtPrivate::FunctionPointer<Func2>::ArgumentCount == -1) && (! is_convertible_v<Func2, const char*>)), QMetaObject::Connection>::type QObject::connect(const typename QtPrivate::FunctionPointer<Func>::Object*, Func1, const QObject*, Func2, Qt::ConnectionType) [with Func1 = void (MainWindow1::*)(QString); Func2 = void (FirstTab::*)(QString)]':
E:/Projects/Galvion/FirstTab.cpp:82:12: required from here
C:/Qt/6.4.1/mingw_64/include/QtCore/qobject.h:287:13: error: no type named 'type' in 'struct std::enable_if<false, QMetaObject::Connection>'
C:/Qt/6.4.1/mingw_64/include/QtCore/qobject.h:181:36: note: candidate: 'static QMetaObject::Connection QObject::connect(const QObject*, const char*, const QObject*, const char*, Qt::ConnectionType)'
181 | static QMetaObject::Connection connect(const QObject *sender, const char *signal,
| ^~~~~~~
C:/Qt/6.4.1/mingw_64/include/QtCore/qobject.h:181:79: note: no known conversion for argument 2 from 'void (MainWindow1::*)(QString)' to 'const char*'
181 | static QMetaObject::Connection connect(const QObject *sender, const char *signal,
| ~~~~~~~~~~~~^~~~~~
C:/Qt/6.4.1/mingw_64/include/QtCore/qobject.h:184:36: note: candidate: 'static QMetaObject::Connection QObject::connect(const QObject*, const QMetaMethod&, const QObject*, const QMetaMethod&, Qt::ConnectionType)'
184 | static QMetaObject::Connection connect(const QObject *sender, const QMetaMethod &signal,
| ^~~~~~~
C:/Qt/6.4.1/mingw_64/include/QtCore/qobject.h:184:86: note: no known conversion for argument 2 from 'void (MainWindow1::*)(QString)' to 'const QMetaMethod&'
184 | static QMetaObject::Connection connect(const QObject *sender, const QMetaMethod &signal,
| ~~~~~~~~~~~~~~~~~~~^~~~~~
C:/Qt/6.4.1/mingw_64/include/QtCore/qobject.h:432:32: note: candidate: 'QMetaObject::Connection QObject::connect(const QObject*, const char*, const char*, Qt::ConnectionType) const'
432 | inline QMetaObject::Connection QObject::connect(const QObject *asender, const char *asignal,
| ^~~~~~~
C:/Qt/6.4.1/mingw_64/include/QtCore/qobject.h:432:85: note: no known conversion for argument 2 from 'void (MainWindow1::*)(QString)' to 'const char*'
432 | inline QMetaObject::Connection QObject::connect(const QObject *asender, const char *asignal,
| ~~~~~~~~~~~~^~~~~~~
[3/4] Building CXX object CMakeFiles/Galvion.dir/mainwindow1.cpp.obj
ninja: build stopped: subcommand failed.
Edit: I forgot to mention that the QWidget FirstTab
has and object name, so it should be finding it correctly
Reading the error message may be tricky sometimes. The key is:
C++ doesn't allow automatic conversion from a base class (
QWidget
) to a derived class (FirstTab
) as not allQWidget
s areFirstTab
s. So you should perform the conversion yourself. In general this could be safely achieved usingqobject_cast
, but in this case requesting aFirstTab
instance instead of a generalQWidget
seems to be the best approach: