Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Invalid conversion in a simple 'hello world' zero widget cmake project on app.exec();



  • Hi,

    I hope I posted on the right subforum.
    I created a very, very simple project without any widgets in the QApplication object and tried to run it.
    The code:

    #include <QApplication>
    
    int main(int argc, char* argv[]) {
        QApplication qapp(argc, argv);
        return qapp.exec;
    }
    

    cmake .pro:

    QT += core gui
    greaterThan(QT_MAJOR_VERSION, 4) : QT += widgets
    SOURCES += \
        sause.cpp
    
    

    I get the following error on compile-time:

    sause.cpp:5: error: invalid conversion from 'int (*)()' to 'int' [-fpermissive]
         return qapp.exec;
                     ^
    

    I think the code is fine, because argv should point to the first element in the array of argv[], no problem there. To be sure though, I tried converting argv into a memory path (&argv), but that didn't work.

    Anything I could try? Is this an installation problem? Missing kits, bad compiler?
    my kit and compiler


  • Moderators

    Hi, welcome to the forum.
    The error says it: error: invalid conversion from 'int (*)()' to 'int' which means you're trying to convert a function pointer to an int.

    Change

    return qapp.exec; //taking an address of a function
    

    to

    return qapp.exec(); //calling a function
    

    and you'll be good to go.



  • I am so dumb :D


Log in to reply