Error : "Cannot take the address of an rvalue of type 'void' "
-
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:
The method called - which compiles without a problem - is this one:
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
-
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:
The method called - which compiles without a problem - is this one:
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
@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. -
@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.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'?
-
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'?
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.
-
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.
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")
-
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")
@MortyMars
You would normally writethis->CalculFixType(...)
or justCalculFixType(...)
where you haveFixWindow::CalculFixType(...)
in the lambda's body. -
@MortyMars
You would normally writethis->CalculFixType(...)
or justCalculFixType(...)
where you haveFixWindow::CalculFixType(...)
in the lambda's body. -
OK, thank you @JonB for that clarification.
I'm still having a bit of trouble understanding what 'this' means in different contexts...
@MortyMars "this" is always the pointer to the current class instance
-
OK, thank you @JonB for that clarification.
I'm still having a bit of trouble understanding what 'this' means in different contexts...
@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 wantthis->methodName
(or just plainmethodName
, you don't need to insert thethis->
before it)! -
@MortyMars "this" is always the pointer to the current class instance
@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 ;-)
-
@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 wantthis->methodName
(or just plainmethodName
, you don't need to insert thethis->
before it)!@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 :-) -
M MortyMars has marked this topic as solved on