我正在做一个QT应用程序。我有一个MainWindow1
类和一个FirstTab
类。MainWindow1
类是一个QMainWindow
,在里面我创建了这个信号-〉
主窗口1.h
signals:
void loadDateSig(QString strDate);
在FirstTab
中,我创建了这个插槽-〉
第一个选项卡.h
public slots:
void loadDate(QString date);
Q_Object
在MainWindow1
和FirstTab
中都有定义。现在在我的MainWindow1
构造函数中,我是这样开始的-〉
主窗口1.cpp
MainWindow1::MainWindow1()
: mainWidget(new QTabWidget) {
setCentralWidget(mainWidget);
mainWidget->addTab(new FirstTab(mainWidget), "First");
createActions();
createStatusBar();
在这下面,我开始做一些连接。我连接了几个项目来改变文档被修改的状态。你可以在这里看到它们,这些工作没有问题-〉
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);
现在我试着连接我的loadDateSig
和loadDate
。我试着在子类和父类中创建连接。但是都给予了我一个错误。我试着像以前那样连接-〉
connect(this, &MainWindow1::loadDateSig, mainWidget->findChild<QWidget *>("tab1"), &FirstTab::loadDate);
然而,这似乎不工作。我得到这些错误-〉
====================[ 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.
有谁能帮我弄清楚为什么会这样吗?
我尝试在FirstTab
类中创建连接。将mainwindow1.cpp
中的父类从mainWidget
parent更改为this
,以便子类可以访问信号-〉
mainWidget->addTab(new FirstTab(this), "First");
然后在FirstTab.cpp
-〉中创建此连接
connect(parent, &MainWindow1::loadDateSig, this, &FirstTab::loadDate);
我在尝试构建-〉时遇到此错误
====================[ 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.
编辑:我忘了提到QWidget FirstTab
有一个对象名,所以它应该能正确地找到它
1条答案
按热度按时间mnemlml81#
阅读错误信息有时可能很棘手。关键是:
从'QWidget*'到'const Object*'的转换无效{也称为'const FirstTab *'}
C++不允许从基类自动转换(
QWidget
)到派生类(FirstTab
),因为不是所有的QWidget
都是FirstTab
。所以您应该自己执行转换。一般来说,使用qobject_cast
可以安全地完成转换,但在这种情况下,请求FirstTab
示例而不是常规的QWidget
似乎是最好的方法: