[solved] error with connecting functions to button

  • 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");

    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]

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

  • It worked ..Thank u for the reply..

  • Moderators

    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.

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.