i am trying to use QShortcut, and declare in in widget constructor like:
QShortcut *keyCtrlL;
keyCtrlL = new QShortcut(this);
keyCtrlL->setKey(Qt::CTRL Qt::Key_L);
connect(keyCtrlL, &QShortcut::activated, this, &MyPage::loadB);
I am not sure it will work, even it compile fine, as variable is local in the constructor. So i am trying to declare it as a private variable for the whole class MyPage,
and getting compilation errors:
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);
Even MyPage is inherited from QWidget. Why this error happens, how can i fix it?
CodePudding user response:
You may be missing #include
of MyPage
header... Without it, it cannot upcast MyPage*
to QWidget*
. Check if it is not missing.