Compare with string and print the value assigned to the letter
-
struct Property { QString data3[1]; QString properties[1]; }; QVector<Property> property; property = { {{ "М2"}, {"Single thread modification."}}, {{ "М" }, {"Single thread modification."}}, {{ " " }, {"Single thread modification."}}, {{ "D" }, {"Modification for two threads" }}, }; for (int i = 0; i < property.size(); i++) { if (data3.at(0)==data_[3] || data3.at(1)==data_[3]) return description = property.properties(0); }
Confused.
I compare with the string: if there is one of the values, the message Single thread modification or Modification for two threads is displayed.
Now nothing is displayed -
struct Property { QString data3[1]; QString properties[1]; }; QVector<Property> property; property = { {{ "М2"}, {"Single thread modification."}}, {{ "М" }, {"Single thread modification."}}, {{ " " }, {"Single thread modification."}}, {{ "D" }, {"Modification for two threads" }}, }; for (int i = 0; i < property.size(); i++) { if (data3.at(0)==data_[3] || data3.at(1)==data_[3]) return description = property.properties(0); }
Confused.
I compare with the string: if there is one of the values, the message Single thread modification or Modification for two threads is displayed.
Now nothing is displayed@fender
Before beginning to decipher your code/address your question: in yourstruct Property
you define thedata3
&properties
members as arrays ofQString
s, each holding just 1 element.Is that really what you intend, or should a single
Property
instance hold just one (of each)data3
&properties
QString
? -
@fender
Before beginning to decipher your code/address your question: in yourstruct Property
you define thedata3
&properties
members as arrays ofQString
s, each holding just 1 element.Is that really what you intend, or should a single
Property
instance hold just one (of each)data3
&properties
QString
? -
struct Property { QString data3[1]; QString properties[1]; }; QVector<Property> property; property = { {{ "М2"}, {"Single thread modification."}}, {{ "М" }, {"Single thread modification."}}, {{ " " }, {"Single thread modification."}}, {{ "D" }, {"Modification for two threads" }}, }; for (int i = 0; i < property.size(); i++) { if (data3.at(0)==data_[3] || data3.at(1)==data_[3]) return description = property.properties(0); }
Confused.
I compare with the string: if there is one of the values, the message Single thread modification or Modification for two threads is displayed.
Now nothing is displayed -
@JonB
That's right, you understand, an array with one elementEach letter / number from the line has its own decryption
For example: SAB-A-F-30-1-M2
Decryption
A - text
F - text
30 - text
1 - text
M2 - Single thread modificationI admit I am not the world's expert C++-er, but:
-
Where are the declarations/values of all the local variables or member variables you do not show (
data3
,data_
,description
)? -
Following on from that: your
data3.at()
do not refer to thedata3
in yourProperty
/property
. Is that really right? -
What is
property.properties(0)
supposed to refer to? -
Are you indeed intending an assignment rather than a comparison in the
return
result?
Also, I'm surprised statements like
property.properties(0)
even compile.... -
-
struct Property { QString data3[1]; QString properties[1]; }; QVector<Property> property; property = { {{ "М2"}, {"Single thread modification."}}, {{ "М" }, {"Single thread modification."}}, {{ " " }, {"Single thread modification."}}, {{ "D" }, {"Modification for two threads" }}, }; for (int i = 0; i < property.size(); i++) { if (data3.at(0)==data_[3] || data3.at(1)==data_[3]) return description = property.properties(0); }
Confused.
I compare with the string: if there is one of the values, the message Single thread modification or Modification for two threads is displayed.
Now nothing is displayedhi @fender
this
return description = property.properties(0);
is not a comparison, but an assignment.
I'm not sure what's supposed to be return bool? QString ? I'm also not sure about the order of execution here, description might be return befor it gets it's new value.
-
hi @fender
this
return description = property.properties(0);
is not a comparison, but an assignment.
I'm not sure what's supposed to be return bool? QString ? I'm also not sure about the order of execution here, description might be return befor it gets it's new value.
@J.Hilk
In case you're asking: the code as written will return the value assigned todescription
, which I presume to beQString
. And as I said probably not what the OP intended?For my edification, could you explain to me how the user;s code compiles:
QVector<Property> property; ... return description = property.properties(0);
Even if we ignore the
description
, what isproperty.properties(0)
at compilation-time?? -
@J.Hilk
In case you're asking: the code as written will return the value assigned todescription
, which I presume to beQString
. And as I said probably not what the OP intended?For my edification, could you explain to me how the user;s code compiles:
QVector<Property> property; ... return description = property.properties(0);
Even if we ignore the
description
, what isproperty.properties(0)
at compilation-time??@JonB
I'm a bit lost about that myself,
maybe the op has omitted a function declaration in the struct, because neither arrays nor QString support direct access via()
.If It's a typo and it's meant to be
[]
than it would be a QChar or QCharRef -
@JonB
I'm a bit lost about that myself,
maybe the op has omitted a function declaration in the struct, because neither arrays nor QString support direct access via()
.If It's a typo and it's meant to be
[]
than it would be a QChar or QCharRefmaybe the op has omitted a function declaration in the struct
My point is that
QVector<Property> property
makesproperty
aQVector<Property>
avector ofProperty
s, it's not astruct Property
. So theproperty.properties
the OP uses has nothing to do with theproperties
member instruct Property
.properties
would need to be a member of theQVector
, not thestruct
.... -
QVector<Property> property; property = { {{ "М2"}, {"Single thread modification."}}, {{ "М" }, {"Single thread modification."}}, {{ " " }, {"Single thread modification."}}, {{ "D" }, {"Modification for two threads" }}, };
You try to populate an array of Property struct, but that doesn't work for a container.
Populate an array of struct:
struct Property { QString data3; QString properties; }; Property properties[] = { { "М2", "Single thread modification."}, { "М", "Single thread modification."}, { " ", "Single thread modification."}, { "D", "Modification for two threads" }, };
Populate a vector:
QVector<Property> _properties; _properties<< Property {"М2", "Single thread modification."} << Property { "М", "Single thread modification."} << Property { " ", "Single thread modification."} << Property { "D", "Modification for two threads" };
Access to values:
// array for (int i = 0; i < sizeof(properties)/sizeof(Property); i++) { qDebug()<<properties[i].data3; } // vector for (Property p : _properties) { qDebug()<<p.data3; }
-
I admit I am not the world's expert C++-er, but:
-
Where are the declarations/values of all the local variables or member variables you do not show (
data3
,data_
,description
)? -
Following on from that: your
data3.at()
do not refer to thedata3
in yourProperty
/property
. Is that really right? -
What is
property.properties(0)
supposed to refer to? -
Are you indeed intending an assignment rather than a comparison in the
return
result?
Also, I'm surprised statements like
property.properties(0)
even compile....@JonB
I have a stringQString MainWindow::dataString() const { QString format = "%0%1%2%3%4%5%6%7%8%9%10%11"; format .arg(data_[0]) .arg(data_[1]) .arg(data_[2]) .arg(data_[3]) .arg(data_[4]) .arg(data_[5]) .arg(data_[6]) .arg(data_[7]) .arg(data_[8]) .arg(data_[9]) .arg(data_[10]) .arg(data_[11]); return format; }
The idea was as follows: if the date [3] contains "M2", then the following tab displays the decryption "M2 - Single thread modification."
So I tried to compare the value from the array with the string and if it matches the output text -
-
@JonB
I have a stringQString MainWindow::dataString() const { QString format = "%0%1%2%3%4%5%6%7%8%9%10%11"; format .arg(data_[0]) .arg(data_[1]) .arg(data_[2]) .arg(data_[3]) .arg(data_[4]) .arg(data_[5]) .arg(data_[6]) .arg(data_[7]) .arg(data_[8]) .arg(data_[9]) .arg(data_[10]) .arg(data_[11]); return format; }
The idea was as follows: if the date [3] contains "M2", then the following tab displays the decryption "M2 - Single thread modification."
So I tried to compare the value from the array with the string and if it matches the output text-
Your original code is so all-over-the-place/uncompilable/unintelligible that it's hard to help.
-
Your new code seems to have nothing to do with it.
-
Your new code will not work as you might think it does because when you read http://doc.qt.io/qt-5/qstring.html#arg (you did read that, didn't you?) you see that it does not alter your
format
variable --- which specifies a format --- but rather returns a newQString
which is the result of applying the formatting.
I don't wish to sound harsh, but you really need to gather your ideas together a bit more carefully, and perhaps look at some other peoples' examples of C++ coding in general if you hope to get anywhere useful.
-