1

How Can I deserialize the output QVariant to std::string without using QT.

by reqs, My program could not include a Qt.

QVariant.toString().toStdString();

Example.

file.ini (write with QSetting) ..

ID="\x1\0\0\0\xd0\x8c\xd9\xec\xfb*"

profile_program /* Pseudo Code */

int main ()
{
   void* IDQt =getIDFromIniFile("file.ini");
   std::string myId = convertID(IDQt);
   process(myID);
}
Agus
  • 1,604
  • 2
  • 23
  • 48
  • 3
    How do you have a `QVariant` and then have the restriction of not being able to call its public members? – Joe May 11 '12 at 12:58
  • There a program that save data into a Ini file with QT. The data is record as "\x1\0\0\0\xd0\x8c\x9d\xdf\x1\x" so that I need to convert to char* to process them – Agus May 11 '12 at 13:04
  • 3
    To clarify you are wanting to deserialize the output from a QVariant in a project that does not include Qt. You have incorrectly worded your original question, I recommend you edit your post and add an example. – Joe May 11 '12 at 13:08
  • Using a proper clearly defined format for data exchange isn't possible? XML, JSon etc. – Frank Osterfeld May 15 '12 at 06:44

1 Answers1

1

Look in the sources, probably src/corelib/kernel/qvariant.cpp for QDataStream& operator<<(QDataStream&, const QVariant&). That way you'll know what gets written during serialization.

Once you do, you'll see that the operator<< calls QVariant::save(QDataStream&). What's written is as follows:

quint32 QVariant::type()
quint8 QVariant::isNull()
if type()==UserType
  QString MetaType::typeName(userType())
end
if the variant is not valid
  QString empty
else
  -- MetaType::save(...)
end

You need to drill down into QString and QMetaType to figure out how those are serialized.

Kuba hasn't forgotten Monica
  • 95,931
  • 16
  • 151
  • 313