Trolltech Home | QSA-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 1

QSA-interest Archive, June 2006
properies and custom types


Message 1 in thread

I want to use property of my custom type.

1. I create 2 classes for my custom type (register by Q_METATYPE, 
qRegisterMetaType)
simular to
class Type1 : public QObject
{
   ...
};

class Type2 : public QObject
{
Q_OBJECT
Q_PROPERTY (Type1 value READ value WRITE setValue)
public:
 ...
public slots:
    Type1 value() const;
    void setValue(const Type1&);

    QString toString() const
    {
        return theValue.toString();
    }

private:
    Type1 theValue;
}

2. I create QSObjectFactory for creating my custom types and add it into 
QSInterpreter
3. Then I use:
///////////////////////////
var variable1:Type1, variable2:Type2;
// init values
....

variable2.value = variable1;
System.println(variable2.toString());
variable1 = variable2.value;
System.println(variable1.toString());
/////////////////////////////
Values of  Type1 are incorrect ...


What do I do wrong?


To unsubscribe - send "unsubscribe" in the subject to qsa-interest-request@xxxxxxxxxxxxx


Message 2 in thread

Cepera wrote:
> I want to use property of my custom type.
> 
> 1. I create 2 classes for my custom type (register by Q_METATYPE, 
> qRegisterMetaType)
> simular to
> class Type1 : public QObject
> {
>   ...
> };
> 
> class Type2 : public QObject
> {
> Q_OBJECT
> Q_PROPERTY (Type1 value READ value WRITE setValue)

Hi Cepera,

There is a bug in QSA 1.2.1 which prevents custom registered metatypes 
from working so you won't be able to do this with the current version.

Please note however that what you are doing is wrong in any case as you 
are trying to use a QObject as a value type. This will crash, assert or 
fail in some other way...

-
Gunnar

To unsubscribe - send "unsubscribe" in the subject to qsa-interest-request@xxxxxxxxxxxxx


Message 3 in thread

"Gunnar Sletta" wrote:

> Please note however that what you are doing is wrong in any case as you 
> are trying to use a QObject as a value type. This will crash, assert or 
> fail in some other way...
>

Instead of this I should use Type1 and Type2 (not QObject), and make wrapers 
(QObject) for using my custom types in Qsa, is it right? 

To unsubscribe - send "unsubscribe" in the subject to qsa-interest-request@xxxxxxxxxxxxx


Message 4 in thread

Cepera wrote:

> Instead of this I should use Type1 and Type2 (not QObject), and make 
> wrapers (QObject) for using my custom types in Qsa, is it right?

But wrappers are only for pointer types, so that won't work 
unfortunatly. We are looking at how extension can be made smoother in 
the next version of QSA.

-
Gunanr


To unsubscribe - send "unsubscribe" in the subject to qsa-interest-request@xxxxxxxxxxxxx