'QShortcut - how to correcly declare in widget?
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?
Solution 1:[1]
You may be missing #include of MyPage header... Without it, it cannot upcast MyPage* to QWidget*. Check if it is not missing.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | HiFile the best file manager |
