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. Error : "Cannot take the address of an rvalue of type 'void' "
Forum Updated to NodeBB v4.3 + New Features

Error : "Cannot take the address of an rvalue of type 'void' "

Scheduled Pinned Locked Moved Solved General and Desktop
11 Posts 4 Posters 2.4k Views 2 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.
  • MortyMarsM Offline
    MortyMarsM Offline
    MortyMars
    wrote on last edited by
    #1

    Hello everyone,

    Thanks to the help of the forum, I'm making progress with my project, but a new problem has arisen with this error: "cannot take the address of an rvalue of type 'void'".

    The error is there:
    Capture d’écran 2024-04-18 à 23.37.55.jpg

    The method called - which compiles without a problem - is this one:
    Capture d’écran 2024-04-18 à 23.38.49.jpg

    So far (but my experience is almost non-existent) I've never encountered this problem when 'connecting' and I have the impression that the blocking comes from the call to a method requiring parameters...

    Thank you for your suggestions

    JonBJ 1 Reply Last reply
    0
    • MortyMarsM MortyMars

      Hello everyone,

      Thanks to the help of the forum, I'm making progress with my project, but a new problem has arisen with this error: "cannot take the address of an rvalue of type 'void'".

      The error is there:
      Capture d’écran 2024-04-18 à 23.37.55.jpg

      The method called - which compiles without a problem - is this one:
      Capture d’écran 2024-04-18 à 23.38.49.jpg

      So far (but my experience is almost non-existent) I've never encountered this problem when 'connecting' and I have the impression that the blocking comes from the call to a method requiring parameters...

      Thank you for your suggestions

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by JonB
      #2

      @MortyMars
      Please post code text not images. I have to type in what the image shows now.

      You cannot have &FixWiindow::CalculFixType(0,1) for a "PointerToMemberFunction method". It must be a (pointer to a) method like &FixWiindow::CalculFixType, no parentheses. Normally a slot takes any parameters passed by the signal. If you intend to call that function with some parameters of your own use a lambda instead.

      MortyMarsM 1 Reply Last reply
      2
      • JonBJ JonB

        @MortyMars
        Please post code text not images. I have to type in what the image shows now.

        You cannot have &FixWiindow::CalculFixType(0,1) for a "PointerToMemberFunction method". It must be a (pointer to a) method like &FixWiindow::CalculFixType, no parentheses. Normally a slot takes any parameters passed by the signal. If you intend to call that function with some parameters of your own use a lambda instead.

        MortyMarsM Offline
        MortyMarsM Offline
        MortyMars
        wrote on last edited by
        #3

        @JonB

        Thank, and sorry for the extra work :-(

        A little late, but the offending code is here:

        connect(ui->cboWP0_1, &QComboBox::textActivated,
               this, &FixWindow::CalculFixType(0,1) );
        

        And the method called, here :

        // VERSION 2 ADAPTEE A TOUTES LES TRIPLETTES DE COMBOBOX
        void FixWindow::CalculFixType(int col, int ligne)
        {
            // Recup des codes ASCII de chaque lettre des 3 combobox
            // Les codes, à ce stade, sont en base 10
            int ASC1 = ComboMatrix.at(col).at(ligne)->currentText().left(1).at(0).toLatin1();
            int ASC2 = ComboMatrix.at(col+1).at(ligne)->currentText().left(1).at(0).toLatin1();
            int ASC3 = ComboMatrix.at(col+2).at(ligne)->currentText().left(1).at(0).toLatin1();
        
            // Conversion des codes en base 16 et inversion de l'ordre
            // pour constituer la chaine hexa à reconvertir en base 10
            QString HexaStr = QString("%1").arg(ASC3, 2, 16, QLatin1Char('0')) +
                              QString("%1").arg(ASC2, 2, 16, QLatin1Char('0')) +
                              QString("%1").arg(ASC1, 2, 16, QLatin1Char('0')) ;
        
            // Conversion de la chaine en entier en base 10
            bool ok;
            int DeciNum = HexaStr.toInt(&ok,16);
        
        
            TxtMatrix.at(ligne)->setText(QString::number(DeciNum));
        
        }
        

        What exactly do you mean by a 'lambda'?

        C 1 Reply Last reply
        0
        • MortyMarsM MortyMars

          @JonB

          Thank, and sorry for the extra work :-(

          A little late, but the offending code is here:

          connect(ui->cboWP0_1, &QComboBox::textActivated,
                 this, &FixWindow::CalculFixType(0,1) );
          

          And the method called, here :

          // VERSION 2 ADAPTEE A TOUTES LES TRIPLETTES DE COMBOBOX
          void FixWindow::CalculFixType(int col, int ligne)
          {
              // Recup des codes ASCII de chaque lettre des 3 combobox
              // Les codes, à ce stade, sont en base 10
              int ASC1 = ComboMatrix.at(col).at(ligne)->currentText().left(1).at(0).toLatin1();
              int ASC2 = ComboMatrix.at(col+1).at(ligne)->currentText().left(1).at(0).toLatin1();
              int ASC3 = ComboMatrix.at(col+2).at(ligne)->currentText().left(1).at(0).toLatin1();
          
              // Conversion des codes en base 16 et inversion de l'ordre
              // pour constituer la chaine hexa à reconvertir en base 10
              QString HexaStr = QString("%1").arg(ASC3, 2, 16, QLatin1Char('0')) +
                                QString("%1").arg(ASC2, 2, 16, QLatin1Char('0')) +
                                QString("%1").arg(ASC1, 2, 16, QLatin1Char('0')) ;
          
              // Conversion de la chaine en entier en base 10
              bool ok;
              int DeciNum = HexaStr.toInt(&ok,16);
          
          
              TxtMatrix.at(ligne)->setText(QString::number(DeciNum));
          
          }
          

          What exactly do you mean by a 'lambda'?

          C Offline
          C Offline
          ChrisW67
          wrote on last edited by
          #4

          This is what your connect should look like:

          connect(ui->cboWP0_1, &QComboBox::textActivated, this, &FixWindow::CalculFixType);
          

          except this will also fail. QComboBox::textActivated() is going to pass a QString value to any slot you connect it to. Typically that slot needs to accept the string as a parameter. Your proposed slot expects two integer arguments.

          In this context, a C++ lambda expression is an unnamed callable code block that can accept/capture parameters and act as the target of a connect (in place of &FixWindow::CalculFixType). Something roughly like this (unable to test at the moment):

          connect(
            ui->cboWP0_1, &QComboBox::textActivated, 
            this, [&, c = 0, l = 1](const QString &text) {
              this->CalculFixType(c, l);
            }
          );
          

          I am sure some more frequent lambda user will correct this.

          If you are doing this for a matrix of combo boxes then there are other ways you could achieve this.

          MortyMarsM 1 Reply Last reply
          3
          • C ChrisW67

            This is what your connect should look like:

            connect(ui->cboWP0_1, &QComboBox::textActivated, this, &FixWindow::CalculFixType);
            

            except this will also fail. QComboBox::textActivated() is going to pass a QString value to any slot you connect it to. Typically that slot needs to accept the string as a parameter. Your proposed slot expects two integer arguments.

            In this context, a C++ lambda expression is an unnamed callable code block that can accept/capture parameters and act as the target of a connect (in place of &FixWindow::CalculFixType). Something roughly like this (unable to test at the moment):

            connect(
              ui->cboWP0_1, &QComboBox::textActivated, 
              this, [&, c = 0, l = 1](const QString &text) {
                this->CalculFixType(c, l);
              }
            );
            

            I am sure some more frequent lambda user will correct this.

            If you are doing this for a matrix of combo boxes then there are other ways you could achieve this.

            MortyMarsM Offline
            MortyMarsM Offline
            MortyMars
            wrote on last edited by
            #5

            @ChrisW67

            Great !!! Thanks Chris,
            With a little adaptation of the code (see below), it works perfectly:

            connect(ui->cboWP0_1, &QComboBox::textActivated,
                        this, [&, col=0, ligne=1]{FixWindow::CalculFixType(col,ligne);} );
            

            I had an "expected body of lambda expression" error, corrected by adding {...}

            And you're right, this method uses a combobox matrix (calculation of the numerical code of an "Enroute and Terminal Waypoint")

            JonBJ 1 Reply Last reply
            0
            • MortyMarsM MortyMars

              @ChrisW67

              Great !!! Thanks Chris,
              With a little adaptation of the code (see below), it works perfectly:

              connect(ui->cboWP0_1, &QComboBox::textActivated,
                          this, [&, col=0, ligne=1]{FixWindow::CalculFixType(col,ligne);} );
              

              I had an "expected body of lambda expression" error, corrected by adding {...}

              And you're right, this method uses a combobox matrix (calculation of the numerical code of an "Enroute and Terminal Waypoint")

              JonBJ Offline
              JonBJ Offline
              JonB
              wrote on last edited by
              #6

              @MortyMars
              You would normally write this->CalculFixType(...) or just CalculFixType(...) where you have FixWindow::CalculFixType(...) in the lambda's body.

              MortyMarsM 1 Reply Last reply
              0
              • JonBJ JonB

                @MortyMars
                You would normally write this->CalculFixType(...) or just CalculFixType(...) where you have FixWindow::CalculFixType(...) in the lambda's body.

                MortyMarsM Offline
                MortyMarsM Offline
                MortyMars
                wrote on last edited by
                #7

                OK, thank you @JonB for that clarification.

                I'm still having a bit of trouble understanding what 'this' means in different contexts...

                jsulmJ JonBJ 2 Replies Last reply
                0
                • MortyMarsM MortyMars

                  OK, thank you @JonB for that clarification.

                  I'm still having a bit of trouble understanding what 'this' means in different contexts...

                  jsulmJ Offline
                  jsulmJ Offline
                  jsulm
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  @MortyMars "this" is always the pointer to the current class instance

                  https://forum.qt.io/topic/113070/qt-code-of-conduct

                  MortyMarsM 1 Reply Last reply
                  0
                  • MortyMarsM MortyMars

                    OK, thank you @JonB for that clarification.

                    I'm still having a bit of trouble understanding what 'this' means in different contexts...

                    JonBJ Offline
                    JonBJ Offline
                    JonB
                    wrote on last edited by
                    #9

                    @MortyMars
                    To do Object-Oriented/C++ programing you need to understand class vs instance. There will be myriad explanations on the web, so I'm not going to try to explain :)

                    I will say: in code for every one time you need to write ClassName::methodName somewhere there are 99 cases where you want this->methodName (or just plain methodName, you don't need to insert the this-> before it)!

                    MortyMarsM 1 Reply Last reply
                    0
                    • jsulmJ jsulm

                      @MortyMars "this" is always the pointer to the current class instance

                      MortyMarsM Offline
                      MortyMarsM Offline
                      MortyMars
                      wrote on last edited by
                      #10

                      @jsulm said in Error : "Cannot take the address of an rvalue of type 'void' ":

                      @MortyMars "this" is always the pointer to the current class instance

                      Thank you for this clear and precise reminder ;-)

                      1 Reply Last reply
                      0
                      • JonBJ JonB

                        @MortyMars
                        To do Object-Oriented/C++ programing you need to understand class vs instance. There will be myriad explanations on the web, so I'm not going to try to explain :)

                        I will say: in code for every one time you need to write ClassName::methodName somewhere there are 99 cases where you want this->methodName (or just plain methodName, you don't need to insert the this-> before it)!

                        MortyMarsM Offline
                        MortyMarsM Offline
                        MortyMars
                        wrote on last edited by
                        #11

                        @JonB
                        Far be it from me to ask you for basic lessons (sorry for my often naive questions) but I've only recently started learning C++ again and a lot of reflexes have been lost.
                        So thank you in advance for your patience, I'm improving (I think) a little more every day ;-)
                        And thank you of course for all your tips and advice :-)

                        1 Reply Last reply
                        0
                        • MortyMarsM MortyMars has marked this topic as solved on

                        • Login

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