Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt Creator and other tools
  4. Invalid conversion in a simple 'hello world' zero widget cmake project on app.exec();
Forum Updated to NodeBB v4.3 + New Features

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

Scheduled Pinned Locked Moved Solved Qt Creator and other tools
3 Posts 2 Posters 525 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.
  • T Offline
    T Offline
    TheTobruk
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • Chris KawaC Offline
      Chris KawaC Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      5
      • T Offline
        T Offline
        TheTobruk
        wrote on last edited by TheTobruk
        #3

        I am so dumb :D

        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