qvariant

QVariant and qRegisterMetaType question

I have a class Pkg and I need to use it under form of QVariant. At the end of my Pkg.h I have: Q_DECLARE_METATYPE(Pkg) and this does not give compile errors, but in my main.cpp I have to do: qRegisterMetaType<Pkg>("Pkg"); and this does not give errors too, but when I try to create a QVariant(Pkg) I get lots of errors like: In me...

Problem with QVariant/QTreeWidgetItem/iterator on qt4.4.3

Hello, here's my problem: In my qt app I have this object, filled before setting up my QTreeWidget's content: QList<QTreeWidgetItem*> items; I fill the QList by this way: QVariant qv; // I need this for "attaching" to the item my linuxPackage object qv.setValue(linuxPackage); packRow->setData(1, Qt::UserRole,qv); // packRow is m...

Convert a QVariant of a custom type to a QString.

I have a custom class called Money that I have declared with Q_DECLARE_METATYPE(). class Money { public: Money(double d) { _value = d; } ~Money() {} QString toString() const { return QString(_value); } private: double _value; }; Q_DECLARE_METATYPE(Money); Money m(23.32); I store that in a QVariant and I want to co...

Is there a possibility to automatically convert QVariants to Python objects?

PyQt 4.5.4, Python 2.6.2 Since version 4.5.2 PyQt is able to accept any Python objects where formerly only QVariants were allowed. This leads to some problems: >>> itemModel.data(index, Qt.EditRole) <Product object at 0xb7ce766c> >>> index.data(Qt.EditRole) <QVariant object at 0xb7ce768c> Is there a possibility to remove this inconsi...

Receive data from dbus

Hi there. I need a hint on handling data structures send via DBus. The running service returns an Array of 2-Tuples containing two ints. In Python a(ii). Calling the method from the Qt app returns me: QDBusMessage answer = dbus_iface.call("hello", 'blaaa', 3, 4); QList data = answer.arguments(); qDebug() << answer: QDBusMessage(type=...

How do I get my python object back from a QVariant in PyQt4?

I am creating a subclass of QAbstractItemModel to be displayed in an QTreeView. My index() and parent() function creates the QModelIndex using the QAbstractItemModel inherited function createIndex and providing it the row, column, and data needed. Here, for testing purposes, data is a Python string. class TestModel(QAbstractItemModel):...

How to support comparisons for QVariant objects containing a custom type?

According to the Qt documentation, QVariant::operator== does not work as one might expect if the variant contains a custom type: bool QVariant::operator== ( const QVariant & v ) const Compares this QVariant with v and returns true if they are equal; otherwise returns false. In the case of custom types, their equalnes...

How to verify QVariant of type QVariant::UserType is expected type ?

I'm writing testing code that will automatically iterate thru all Q_PROPERTY's of widgets and some properties are using types that are registered via qRegisterMetaType. If i want to read/write these into QVariant i need to use QVariant::UserType when storing them into variant. So far so good. But when i want to test reads and writes of ...

In QT & C++, Covert QMap<QString, QMap<QString, int> > to a single QVariant type.

Apparently QVariant (needed for QSettings class) supports creation from QMap<QString, QVariant> But trying to initialise something like this: QMap<QString, QVariant(QMap<QString, QVariant>)> i; Returns instantiated from here. <-- points to code above. function returning a function. So then i tried the QMap<QString, QVariant> overlo...