0

Say I have the function...

const QMainWindow* MainWindow::getThis(){
    return this;
}

would it be possible to call this function for the third argument of my SIGNAL/SLOT connection...

QAction* myAction = new QAction("my action!");
connect(myAction, &QAction::triggered, getThis(), &MainWindow::someAction);

(qt creator doesnt like this)

poppy
  • 247
  • 2
  • 15
  • what is the meaning of `qt creator doesnt like this`? – eyllanesc Jul 09 '20 at 23:57
  • mainwindow.cpp:40:5: error: no matching member function for call to 'connect' qobject.h:242:43: note: candidate function [with Func1 = void (QAction::*)(bool), Func2 = void (MainWindow::*)()] not viable: cannot convert from base class pointer 'const QMainWindow *' to derived class pointer 'const typename QtPrivate::FunctionPointer::Object *' (aka 'const MainWindow *') for 3rd argument – poppy Jul 10 '20 at 00:04
  • 2
    Is someAction() a const function? Since you require it to not modify MainWindow – drescherjm Jul 10 '20 at 00:55
  • Maybe have a look here: https://stackoverflow.com/questions/24410130/no-matching-function-for-qobjectconnect It may happen that in the place where you are trying to make a connection QObject is not inherited and Q_OBJECT macro is not declared. – pklimczu Jul 10 '20 at 07:57

0 Answers0