Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Learning
  3. Qt in Education
  4. [solved] error with connecting functions to button
Forum Updated to NodeBB v4.3 + New Features

[solved] error with connecting functions to button

Scheduled Pinned Locked Moved Qt in Education
4 Posts 3 Posters 2.2k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    sarahjohn
    wrote on last edited by
    #1

    Hi..
    Myself trying to write a program in Qt connecting a function to a button in Qt5.
    @
    #include <QApplication>
    #include <QtGui>
    #include <QPushButton>
    static void insert()
    {
    qDebug() << "pressed";
    }

    int main(int argc,char *argv[])
    {
    QApplication app(argc,argv);
    QPushButton *button=new QPushButton("button");
    button->setGeometry(50,100,150,80);
    QObject::connect(button,&QPushButton::clicked,insert());
    button->show();
    }
    @

    But I am getting errors like
    @
    main.cc:23:39: error: within this context
    main.cc:23:55: error: invalid use of void expression
    make: *** [main.o] Error 1
    @

    Please help...

    [code tags and solved, added, koahnig]

    1 Reply Last reply
    0
    • A Offline
      A Offline
      Alek Śmierciak
      wrote on last edited by
      #2

      You supplied the QObject::connect function with a void function outcome as a third parameter while it was expecting a function object or a function pointer. Try this instead:
      @ QObject::connect(button, &QPushButton::clicked, insert);@

      Still, with this code you won't see much; you should implement an application window and put this button inside.

      1 Reply Last reply
      0
      • S Offline
        S Offline
        sarahjohn
        wrote on last edited by
        #3

        It worked ..Thank u for the reply..

        1 Reply Last reply
        0
        • K Offline
          K Offline
          koahnig
          wrote on last edited by
          #4

          Please checkout the ForumHelp for advice on postings. "Code wrappings":http://qt-project.org/wiki/ForumHelp#e3f82045ad0f480d3fb9e0ac2d58fb01 do improve the layout of your posting significantly. I have added them for you this time.

          Vote the answer(s) that helped you to solve your issue(s)

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved