Hi!
I need to convert my user type (MyObject, base class is QObject) to QVariant?
class MyObject : public QObject
{
Q_OBJECT
public slots:
...
};
How convert MyObject to QVariant?
Thanks.
Hi!
I need to convert my user type (MyObject, base class is QObject) to QVariant?
class MyObject : public QObject
{
Q_OBJECT
public slots:
...
};
How convert MyObject to QVariant?
Thanks.
can we ask -- why?
Qt Assistant -- rocks!
please, use tags [CODE] & [/CODE].
anyway, the answer is no, because as Qt Assistants say for Q_DECLARE_METATYPE the following thing:
but QObject's copy constructor is private.This macro makes the type Type known to QMetaType as long as it provides a public default constructor, a public copy constructor and a public destructor.
Qt Assistant -- rocks!
please, use tags [CODE] & [/CODE].
Yes, you can!
Tag: "using standart and user types in QtScript"
I has class, it has function that return several types (int, bool, string, and USER TYPES)
This class I want use in QtScript.
//this objects I use in QtScript!
class Document: public QObject
{
Q_OBJECT
public slots:
QString getName(); //method for use in QtScript
};
//simple example, in real it's hardly
class Catalogue : public OQbject
{
QVariant getValue(QString name)
{
if(fname == "Document")
{
Document doc = new Document();
//try convert to QVariant
return QVariant(doc);
}
else if(fname == "Boolean")
{
return QVariant(true);
}
... //etc.
}
};
next part, QtScript
var cat = new Catalogue();
var doc = cat.getValue("Document");
var flag = cat.getValue("Boolean");
//doc - is not simple object!
//flag - is simple bool object!
var txt = doc.getName();
Function getValue(...) return several type, it's may be simple bool or int type or user type such as Document and other!
If all Qt types was inherited from one base class I have no problem, but ... (in c# all types (int, bool, user types) inherited from Object base class by default)
May be anyone have another decision of this problem?
Thanks for help.
Last edited by sergey_85; 15th December 2009 at 08:15.
QObject has only private copy constructor, but it must be public for Q_DECLARE_METATYPE.
in you example you use pointers.
Qt Assistant -- rocks!
please, use tags [CODE] & [/CODE].
you can keep pointers, but not objects.
Qt Assistant -- rocks!
please, use tags [CODE] & [/CODE].
pointers to void *?>>you can keep pointers, but not objects.
but how it use in QtScript&
var param = cat.getValue(); //here may be int, may be user type
pointers to void, to QObject, to QWidget. take a look at QVariant ctor which takes pointer to void.
Qt Assistant -- rocks!
please, use tags [CODE] & [/CODE].
Bookmarks