PDA

View Full Version : Using the Qt5 connecy syntax



bnosam
9th February 2015, 01:44
When I try to use the newer syntax:



connect(ui->actionOpen_Script, &QAction::triggered(), OpenScript);

or


connect(ui->actionOpen_Script, &QAction::triggered(), &MainWindow::OpenScript);

I get errors:


error: C2352: 'QAction::triggered' : illegal call of non-static member function

What's going on?

jefftee
9th February 2015, 02:19
What's going on?
Remove the parens like this:


connect(ui->actionOpen_Script, &QAction::triggered, &MainWindow::OpenScript);
Hope that helps.

bnosam
9th February 2015, 02:26
Remove the parens like this:


connect(ui->actionOpen_Script, &QAction::triggered, &MainWindow::OpenScript);
Hope that helps.


I get this error now:

E:\Programs\Qt\Qt5.2.1\5.2.1\msvc2010_opengl\inclu de\QtCore\qobject.h:249: error: C2665: 'QObject::connect' : none of the 4 overloads could convert all the argument types
E:\Programs\Qt\Qt5.2.1\5.2.1\msvc2010_opengl\inclu de\QtCore/qobject.h(215): could be 'QMetaObject::Connection QObject::connect<Func1,Func2>(const QAction *,Func1,const MainWindow *,Func2,Qt::ConnectionType)'
with
[
Func1=void (__thiscall QAction::* )(bool),
Func2=void (__thiscall MainWindow::* )(void)
]
E:\Programs\Qt\Qt5.2.1\5.2.1\msvc2010_opengl\inclu de\QtCore/qobject.h(198): or 'QMetaObject::Connection QObject::connect(const QObject *,const char *,const QObject *,const char *,Qt::ConnectionType)'
E:\Programs\Qt\Qt5.2.1\5.2.1\msvc2010_opengl\inclu de\QtCore/qobject.h(201): or 'QMetaObject::Connection QObject::connect(const QObject *,const QMetaMethod &,const QObject *,const QMetaMethod &,Qt::ConnectionType)'
while trying to match the argument list '(const QAction *, void (__thiscall QAction::* )(bool), const QAction *, void (__thiscall MainWindow::* )(void), Qt::ConnectionType)'


Solution:


connect(ui->actionOpen_Script, &QAction::triggered, this, &MainWindow::OpenScript);
That fixed it.

jefftee
9th February 2015, 02:57
Glad you got it to work. I was focused on the problem at hand and didn't notice you were missing the object for the slot... :)