我试图使用QShortcut,并在小部件构造函数中声明如下:
QShortcut *keyCtrlL;
keyCtrlL = new QShortcut(this);
keyCtrlL->setKey(Qt::CTRL + Qt::Key_L);
connect(keyCtrlL, &QShortcut::activated, this, &MyPage::loadB);我不确定它是否能工作,即使它编译得很好,因为变量在构造函数中是本地的。因此,我试图将它声明为整个类MyPage的私有变量,
并获得编译错误:
error: cannot initialize a parameter of type 'QWidget *' with an rvalue of type 'MyPage *'
ui->setupUi(this);
^~~~
./qt/forms/ui_mypage.h:69:27: note: passing argument to parameter 'MyPage' here
void setupUi(QWidget *MyPage)
^
qt/mypage.cpp:153:20: error: no matching constructor for initialization of 'QShortcut'
keyCtrlL = new QShortcut(this);甚至MyPage也是从QWidget继承的。为什么会发生这个错误,我该如何修复呢?
发布于 2022-04-16 09:32:45
你可能丢失了#include of MyPage报头..。没有它,它就不能将MyPage*向上转换为QWidget*。检查它是否不见了。
https://stackoverflow.com/questions/71891288
复制相似问题