Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. What means this error and how can i fix it?
QtWS25 Last Chance

What means this error and how can i fix it?

Scheduled Pinned Locked Moved Unsolved General and Desktop
qpushbutterror
9 Posts 3 Posters 2.7k Views
  • 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.
  • ? Offline
    ? Offline
    A Former User
    wrote on 14 Aug 2016, 12:10 last edited by
    #1

    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
    0
    • ? Offline
      ? Offline
      A Former User
      wrote on 14 Aug 2016, 12:26 last edited by
      #2

      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.

      M 1 Reply Last reply 14 Aug 2016, 12:41
      0
      • ? A Former User
        14 Aug 2016, 12:26

        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.

        M Offline
        M Offline
        mrjj
        Lifetime Qt Champion
        wrote on 14 Aug 2016, 12:41 last edited by mrjj
        #3

        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
        0
        • ? Offline
          ? Offline
          A Former User
          wrote on 14 Aug 2016, 13:39 last edited by
          #4

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

          M 1 Reply Last reply 14 Aug 2016, 13:53
          0
          • ? A Former User
            14 Aug 2016, 13:39

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

            M Offline
            M Offline
            mrjj
            Lifetime Qt Champion
            wrote on 14 Aug 2016, 13:53 last edited by
            #5

            @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
            0
            • ? Offline
              ? Offline
              A Former User
              wrote on 14 Aug 2016, 13:56 last edited by
              #6

              I have it:
              CONFIG += c++11

              1 Reply Last reply
              0
              • ? Offline
                ? Offline
                A Former User
                wrote on 14 Aug 2016, 13:57 last edited by
                #7

                But the error is still there

                1 Reply Last reply
                0
                • M Offline
                  M Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on 14 Aug 2016, 14:09 last edited by mrjj
                  #8

                  oh forum ate some of the syntax

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

                  note the []

                  it removed it before.

                  1 Reply Last reply
                  1
                  • ? Offline
                    ? Offline
                    A Former User
                    wrote on 15 Aug 2016, 07:08 last edited by
                    #9

                    It works,

                    thanks a lot

                    1 Reply Last reply
                    1

                    1/9

                    14 Aug 2016, 12:10

                    • Login

                    • Login or register to search.
                    1 out of 9
                    • First post
                      1/9
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • Users
                    • Groups
                    • Search
                    • Get Qt Extensions
                    • Unsolved