Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Unsolved What means this error and how can i fix it?

    General and Desktop
    qpushbutt error
    3
    9
    1986
    Loading More Posts
    • 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.
    • ?
      A Former User last edited by

      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

      1 Reply Last reply Reply Quote 0
      • ?
        A Former User last edited by

        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.

        mrjj 1 Reply Last reply Reply Quote 0
        • mrjj
          mrjj Lifetime Qt Champion @Guest last edited by mrjj

          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";
           });
          1 Reply Last reply Reply Quote 0
          • ?
            A Former User last edited by

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

            mrjj 1 Reply Last reply Reply Quote 0
            • mrjj
              mrjj Lifetime Qt Champion @Guest last edited by

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

              1 Reply Last reply Reply Quote 0
              • ?
                A Former User last edited by

                I have it:
                CONFIG += c++11

                1 Reply Last reply Reply Quote 0
                • ?
                  A Former User last edited by

                  But the error is still there

                  1 Reply Last reply Reply Quote 0
                  • mrjj
                    mrjj Lifetime Qt Champion @Guest last edited by mrjj

                    oh forum ate some of the syntax

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

                    note the []

                    it removed it before.

                    1 Reply Last reply Reply Quote 1
                    • ?
                      A Former User last edited by

                      It works,

                      thanks a lot

                      1 Reply Last reply Reply Quote 1
                      • First post
                        Last post