I'm trying to send a custom class ( "Span" ) inside a QVariant across the Dbus session bus in Qt between 2 simple applications. I am using Qt Version 4.8.1 ( but see the same results with 4.8.3 ) Span is a simple class that contains 2 double type properties. I have successfully sent and recovered a QVariant containing just a QString across the dbus interface in the same manner I am trying to do below with a QVariant of a custom class.

Span contains the following declaration for the QMETATYPE QVariant registration in the class header file:

Qt Code:
  1. Q_DECLARE_METATYPE(Span)
To copy to clipboard, switch view to plain text mode 

I have 2 test applications, one sender and one receiver - both have exactly the same 'Span' class definitions. In my sender app I do this:

Qt Code:
  1. qDebug() << "Sending QVariant Span to receiver...";
  2. //int spanID = QMetaType::type("Span");
  3. Span span(100,0.5);
  4. //QVariant settingVariant(spanID, &span);
  5. //QVariant settingVariant(QString("HELLO"));
  6. QVariant settingVariant;
  7. settingVariant.setValue(span);
  8.  
  9. QDBusVariant setting( settingVariant );
  10. response = client->setSetting(setting);
  11. qDebug() << "RESPONSE: " << response;
  12.  
  13. QVariant result = setting.variant(); // THIS WORKS - I can just extract my 'Span' here with the correct property values set
  14. QVariant test = QVariant::fromValue(result);
  15. Span testSpan = test.value<Span>();
  16. qDebug() << "Setting Span to -- Low: " << testSpan.m_lowTemp << "High: " << testSpan.m_highTemp;
To copy to clipboard, switch view to plain text mode 

The 'setSetting' method is defined as:

Qt Code:
  1. inline QDBusPendingReply<int> setSetting(const QDBusVariant setting)
  2. {
  3. QList<QVariant> argumentList;
  4. argumentList << QVariant::fromValue(setting);
  5. return asyncCallWithArgumentList(QLatin1String("setSetting"), argumentList);
  6. }
To copy to clipboard, switch view to plain text mode 

In the receiver, I register the 'Span' class like this:

Qt Code:
  1. qRegisterMetaType<Span>();
  2. qDBusRegisterMetaType<Span>();
To copy to clipboard, switch view to plain text mode 

and then I attempt to recover the Span class like so:

Qt Code:
  1. int DbusServerTemplate::setSetting( const QDBusVariant &setting ) {
  2.  
  3. QVariant result = setting.variant();
  4. QVariant test = QVariant::fromValue(result);
  5. Span stuff = test.value<Span>();
  6. qDebug() << "Setting Span to -- Low: " << stuff.m_low << "High: " << stuff.m_high;
To copy to clipboard, switch view to plain text mode 

The above code gives me bogus values for the Span class properties:

Qt Code:
  1. Setting Span to -- Low: 1.44144e-305 High: 5.24729e-261
To copy to clipboard, switch view to plain text mode 

What am I doing wrong? I can encode and decode the Span instance in the Sender app but once the receiver class gets it over dbus I'm getting bogus values. I'd really appreciate any ideas / help!