Abstract type with qmlRegisterType



  • Hi, I've been using abstract classes with QML, and it has been working great until I tried to register a new type, then I get:

    error: cannot allocate an object of abstract type ‘QDeclarativePrivate::QDeclarativeElement<IsAnalogIn>’

    This is easy enough to work around by giving my abstract class an implementation, but that is a hack. Is this a fundamental limitation, or is there something I can do to make this work?



  • I GUESS the idea of registering a new type implies that you can create a new instance of that type later on. In order to create a new instance you need to have a fully implemented class.



  • I haven't tried but you may be able to register the abstract class using
    "qmlRegisterTypeNotAvailable":http://doc.qt.nokia.com/4.7/qdeclarativeengine.html#qmlRegisterTypeNotAvailable



  • Hi, I have the same problem with you now,can you give me some idea to solve this problem .Thanks !

    instantiated from ‘int qmlRegisterType(const char*, int, int, const char*) [with T = Directory]’
    error: cannot allocate an object of abstract type ‘QDeclarativePrivate::QDeclarativeElement<Directory>’
    note: because the following virtual functions are pure within ‘QDeclarativePrivate::QDeclarativeElement<Directory>’:



  • Hi, I have the same problem with you now,can you give me some idea to solve this problem .Thanks !

    instantiated from ‘int qmlRegisterType(const char*, int, int, const char*) [with T = Directory]’
    error: cannot allocate an object of abstract type ‘QDeclarativePrivate::QDeclarativeElement<Directory>’ note: because the following virtual functions are pure within ‘QDeclarativePrivate::QDeclarativeElement<Directory>’:



  • Hi changli85,

    please, don't double post. That's usually seen as spamming the forum. If someone knows an answer he/she will answer.



  • I'm not sure but you also can try "qmlRegisterUncreatableType":http://doc.qt.nokia.com/4.7/qdeclarativeengine.html#qmlRegisterUncreatableType



  • thanks,I have used qmlRegisterUncreatableType ,but the problem can't be solved! Could you give me other idea!thanks
    #ifdef NO_DIRECTORYS_ALLOWED
    qmlRegisterUncreatableType<Directory>("Charts",1,0,"Directory","Get back to work, slacker!");
    #else
    qmlRegisterType<Directory>( "Charts", 1, 0, "Directory" );
    #endif



  • changli85, qmlRegisterUncreatableType should work for abstract classes. Can you elaborate what error do you have, what is Directory class, when this define is defined?



  • Denis Kormalev , Thanks,I have solved this problem.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.