Template function
-
In .cpp file I have this template function:
template <typename M, typename N> void MainWindow::showMenu(M m, N n) { QSize size = m->sizeHint(); m->popup(n->mapToGlobal(QPoint(0,0-size.height()))); }
where
· m = QMenu
· n = QPushPuttonIn what form I should declare this function in the header file?
Thanks in advanve
-
@UnitScan said in Template function:
Hi
That is because the released() signal DO NOT have QMenu* and QPushButton * parameters.You cannot invent new parameters for a signal.
You can define new signals though.http://doc.qt.io/qt-5/signalsandslots.html
also note that connect returns true if connect works.
so
qDebug() << "tcheck:" << connect(xxx) to see if they work.
-
since I hate
sender()
andpb->children().at(0)
is even less robust I suggest (assuming you declaredQMenu* MainWindow::m
):connect(sel, &QPushButton::released, [=]()->void{ const QSize size = m->sizeHint(); m->popup(sel->mapToGlobal(QPoint(0,-size.height()))); });
P.S.
Looking at this functionality, are you sure QToolButton is not a better choice? seeQToolButton::setMenu