i am an amateur in Qt. i started recently. i have read other topic relating to mine in the forum but they all seem close to but not it. so i decided to post my problem as well. i am using QMap as my container class in Qt. whereby i have a QString as my key and another QString and a QDateTime as my value. since i am trying as a test app to build an app that merges messages and dates. so i used a QString as key and a QVariant as my value hoping to contain the object of these two classes that is QString and QDateTime in my QVariant. i managed to insert both objects into the map since QVariant can accept any registered type but my problem is that i cannot bring out the content of my values using the display widgets QTextEdit and QDateTimeEdit. someone please help i have been at this for weeks and i have tried alot of thing and i mean alot.
QMap<QString,QVariant>My_Messages. // my container class.
if(My_Messages.contains(name))
{
QMessageBox::information(this,tr("Add unsuccessful"),
tr("sorry, \"%1\" is already in your message list.").arg(name));
}
else {
future.setValue(text);
My_Messages.insertMulti(name, future);
future.setValue(date);
My_Messages.insertMulti(name, future);
QMessageBox::information(this,tr("Add successful"),
tr("\"%1\" has been added to your message list.").arg(name)); /* this is how i inserted the objects into the variant into the map */
name = key which is a QString.
future = QVariant which stores a QDateTime 'date' and another QString 'text'.
if (My_Messages.contains(messageName)) {
text = future.value<QString>();
textEdit->setText(text);
date = future.value<QDateTime>();
zeit->setDateTime(date);
} else{
QMessageBox::information(this, tr("Name Not Found"),
tr("Sorry, \"%1\" is not in your message list.").arg(messageName));
return;
} /* this is where i tried to display my widgets on screen but failed. because the QTextEdit :: setText function expects a QString as argument and i cant give it a QVariant and also QDateTime :: setDateTime fuction expects a dateTime as arguement and i cant give it a QVariant*/
/* this is where i tried to display my widgets on screen but failed. because the QTextEdit :: setText function expects a QString as argument and i cant give it a QVariant and also QDateTime :: setDateTime fuction expects a dateTime as arguement and i cant give it a QVariant*/