What means this error and how can i fix it?



  • Hello,
    what means this error and how can i fix it?

    C:\Users\henri\Documents\Kodi\Kodi\main.cpp:242: Fehler: could not convert 'fullScreen->QPushButton::<anonymous>.QAbstractButton::click()' from 'void' to 'bool'
             if(fullScreen->click ())
                                  ^
    

    Hallo,
    was bedeutet dieser Fehler und wie kann ich ihn beheben?

    C:\Users\henri\Documents\Kodi\Kodi\main.cpp:242: Fehler: could not convert 'fullScreen->QPushButton::<anonymous>.QAbstractButton::click()' from 'void' to 'bool'
             if(fullScreen->click ())
                                  ^
    

    Complete Code snippet:
    Kompletter Code-Ausschnitt:

    QPushButton *fullScreen = new QPushButton;
            fullScreen->setText ("[ ]");
            fullScreen->resize (15, 15);
            if(fullScreen->click ())
                container->setMinimumSize(QSize(screenSize.width() / 1, screenSize.height() / 1));
    

    Thanks for help,
    danke,

    Henrik



  • Hi! It's declared as void QAbstractButton::click(), so it does not return any value (void) but your if (something) requires something to return a value that is of type bool or that can be implicitely converted to bool.


  • Qt Champions 2016

    Besides @Wieland explanation why it dont work, i would like to add the following

    You can never check for a button being clicked using a function like that.
    " if(fullScreen->click ())"

    You would always need to connect
    connect(button, SIGNAL( clicked() ) , this, SLOT( yourslot))
    and then in the function yourslot do what you want.

    Howver, if u have c++11 enabled , you can cheat a little using something
    called lambda, which allows to define the slot locally.

    like this

    
     connect(loadTextFileButton, &QPushButton::clicked, []()
     {
         qDebug()<<"clicked";
     });


  • Thanks,

    when i copy and paste your Code:

    connect(fullScreen, &QPushButton::clicked, 
    {
    qDebug()<<"clicked";
    });
    

    I geht this:
    error: expected '}'
    note: to match this '{'

    And the ; behind "clicked" is red underlined...


  • Qt Champions 2016

    @HenrikSt.

    hi if you are using mingw compiler, make sure it
    has
    config+=c++11

    in the pro file.

    This enable c++ 11 and that is needed for this syntax.



  • I have it:
    CONFIG += c++11



  • But the error is still there


  • Qt Champions 2016

    oh forum ate some of the syntax

     connect(loadTextFileButton, &QPushButton::clicked, []()
     {
         qDebug()<<"clicked";
     });
    

    note the []

    it removed it before.



  • It works,

    thanks a lot


Log in to reply
 

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