I'm dynamically generating QWidgets (so far only labels) so that I can change the UI on the fly. I know I can use XML files from QTCreator, but I've got my reasons not to.
Anyway, everytime I create a widget, I pass the type (label) and address to a vector. That works fine. But when I try to cast the address back to a QLabel (for example) and do '&castedQLabel' it gives me a different result.
Here is a pseudo code of what is happening:
vector_of_Widgets.push_back({tmpString, "label", &origLabel});
qDebug() << &origLabel;
//Later in code
QLabel *tmpLabel = (QLabel *)vector_of_QWidgets[number].data; //.data is the third argument ^^
qDebug() << vector_of_QWidgets[number].data;
qDebug() << &tmpLabel;
Output:
>>0x7ffc151a5518
>>0x7ffc151a5518
>>0x7ffc151a4ab0
Oh yeah, also, .data is (void *).
tmpLabel指向您的QLabel,无需取消引用它。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.