I get problem when converting a QWidget* to QVariant, please see the following code and its output:
#include <QApplication>
#include <QWidget>
#include <QVariant>
#include <QDebug>
int main(int argc, char *argv[])
{
//you can use all other methods like qVariantFromValue(widget)
qDebug() << "widget-addr=" << widget << "address saved to variant=" << var1;
qDebug() << "object-addr=" << obj << "address saved to variant=" << var2;
}
#include <QApplication>
#include <QWidget>
#include <QVariant>
#include <QDebug>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QWidget *widget= new QWidget();
QObject *obj = widget;
//you can use all other methods like qVariantFromValue(widget)
QVariant var1 = QVariant::fromValue(widget);
QVariant var2 = QVariant::fromValue(obj);
qDebug() << "widget-addr=" << widget << "address saved to variant=" << var1;
qDebug() << "object-addr=" << obj << "address saved to variant=" << var2;
}
To copy to clipboard, switch view to plain text mode
output:
widget-addr= QWidget(0x347748) address saved to variant= QVariant(QWidget*, )
object-addr= QWidget(0x347748) address saved to variant= QVariant(QObject*, QWidget(0x347748) )
Why line 13 doesn't work? Why it doesn't convert QWidget* to QObject* automatically? [I'm using Qt-4.7.3 and minGW]
Bookmarks