[Solved] moc, setProperty
i have a short question concerning the setProperty member of an widget.
In a slot i receive changes in a combobox which has the dynamic property "relatedProperty" set to a property of another widget like "orientation" for example.
The slot procedure extracts the dynamic property. This is used for setting a widgets property depending on the "relatedProperty" value of the combobox and the value of the combobox itself. To achive this behaviour i tried the following c++ code.
char property = sender()->property("relatedProperty").toChar().toAscii();
qDebug() << tempModule.widget->setProperty(&property, Value);
But i only get "false" as output for the last qDebug() line.
I spent a lot of time solving this but i can't find a solution.
I hope someone has good ideas to fixthis problem.
I think I understand what you want and I try to make a solution.
You can try this code:
char *property = new char[relatedProperty.toStdString().size() + 1];
delete  property;@
Tell me if it worked, or if it is not what you need, explain better and we will make it work.
toChar() returns the QVariant as QChar, a single character. This is most probably not what you've meant, because "orientation" usually does not fit into a single character. Use toString() instead.
QByteArray relatedProperty = objectA.property("relatedProperty").toString().toLatin1();
On a sidenote: do not use toAscii(); it is deprecated and will be no longer available in Qt5.
thank you very mouch for your help
works like a charm!
You are welcome. Feel free to edit the thread title to '[Solved] ...' to indicate that there is a solution inside.
And bear in mind that there is a significat performance penalty in using <code>.toStdString().c_str()</code> over <code>.toLatin1().constData()</code>.