Results 1 to 4 of 4

Thread: Using the Qt5 connecy syntax

  1. #1
    Join Date
    Jun 2014
    Posts
    13
    Thanks
    1
    Qt products
    Qt5

    Default Using the Qt5 connecy syntax

    When I try to use the newer syntax:


    Qt Code:
    1. connect(ui->actionOpen_Script, &QAction::triggered(), OpenScript);
    To copy to clipboard, switch view to plain text mode 

    or

    Qt Code:
    1. connect(ui->actionOpen_Script, &QAction::triggered(), &MainWindow::OpenScript);
    To copy to clipboard, switch view to plain text mode 

    I get errors:

    Qt Code:
    1. error: C2352: 'QAction::triggered' : illegal call of non-static member function
    To copy to clipboard, switch view to plain text mode 

    What's going on?

  2. #2
    Join Date
    Dec 2009
    Location
    New Orleans, Louisiana
    Posts
    791
    Thanks
    13
    Thanked 153 Times in 150 Posts
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Re: Using the Qt5 connecy syntax

    Quote Originally Posted by bnosam View Post
    What's going on?
    Remove the parens like this:

    Qt Code:
    1. connect(ui->actionOpen_Script, &QAction::triggered, &MainWindow::OpenScript);
    To copy to clipboard, switch view to plain text mode 
    Hope that helps.

  3. The following user says thank you to jefftee for this useful post:

    bnosam (9th February 2015)

  4. #3
    Join Date
    Jun 2014
    Posts
    13
    Thanks
    1
    Qt products
    Qt5

    Default Re: Using the Qt5 connecy syntax

    Quote Originally Posted by jthomps View Post
    Remove the parens like this:

    Qt Code:
    1. connect(ui->actionOpen_Script, &QAction::triggered, &MainWindow::OpenScript);
    To copy to clipboard, switch view to plain text mode 
    Hope that helps.

    I get this error now:
    Qt Code:
    1. E:\Programs\Qt\Qt5.2.1\5.2.1\msvc2010_opengl\include\QtCore\qobject.h:249: error: C2665: 'QObject::connect' : none of the 4 overloads could convert all the argument types
    2. E:\Programs\Qt\Qt5.2.1\5.2.1\msvc2010_opengl\include\QtCore/qobject.h(215): could be 'QMetaObject::Connection QObject::connect<Func1,Func2>(const QAction *,Func1,const MainWindow *,Func2,Qt::ConnectionType)'
    3. with
    4. [
    5. Func1=void (__thiscall QAction::* )(bool),
    6. Func2=void (__thiscall MainWindow::* )(void)
    7. ]
    8. E:\Programs\Qt\Qt5.2.1\5.2.1\msvc2010_opengl\include\QtCore/qobject.h(198): or 'QMetaObject::Connection QObject::connect(const QObject *,const char *,const QObject *,const char *,Qt::ConnectionType)'
    9. E:\Programs\Qt\Qt5.2.1\5.2.1\msvc2010_opengl\include\QtCore/qobject.h(201): or 'QMetaObject::Connection QObject::connect(const QObject *,const QMetaMethod &,const QObject *,const QMetaMethod &,Qt::ConnectionType)'
    10. while trying to match the argument list '(const QAction *, void (__thiscall QAction::* )(bool), const QAction *, void (__thiscall MainWindow::* )(void), Qt::ConnectionType)'
    To copy to clipboard, switch view to plain text mode 


    Solution:

    Qt Code:
    1. connect(ui->actionOpen_Script, &QAction::triggered, this, &MainWindow::OpenScript);
    To copy to clipboard, switch view to plain text mode 
    That fixed it.
    Last edited by bnosam; 9th February 2015 at 02:53.

  5. #4
    Join Date
    Dec 2009
    Location
    New Orleans, Louisiana
    Posts
    791
    Thanks
    13
    Thanked 153 Times in 150 Posts
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Re: Using the Qt5 connecy syntax

    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...

Similar Threads

  1. Git checkout syntax for Qt version?
    By chouqud in forum Newbie
    Replies: 1
    Last Post: 28th February 2014, 00:46
  2. .pro file syntax
    By lxman in forum Qt Tools
    Replies: 4
    Last Post: 11th February 2011, 23:21
  3. Syntax confusion
    By baluk in forum Newbie
    Replies: 3
    Last Post: 11th December 2010, 15:58
  4. Regarding syntax
    By Yayati.Ekbote in forum Qt Programming
    Replies: 3
    Last Post: 27th January 2010, 14:15
  5. Odd Syntax
    By acxdotfm in forum Qt Programming
    Replies: 2
    Last Post: 24th October 2008, 20:23

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.