Important: Please read the Qt Code of Conduct -

[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
    @ error: within this context 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..

  • Please checkout the ForumHelp for advice on postings. "Code wrappings": do improve the layout of your posting significantly. I have added them for you this time.

Log in to reply