Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Abstract type with qmlRegisterType

    QML and Qt Quick
    6
    10
    8292
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • C
      cbrake last edited by

      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?

      1 Reply Last reply Reply Quote 0
      • F
        fcrochik last edited by

        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.

        Certified Specialist & Qt Ambassador <a href="http://www.crochik.com">Maemo, Meego, Symbian, Playbook, RaspberryPi, Desktop... Qt everywhere!</a>

        1 Reply Last reply Reply Quote 0
        • F
          fcrochik last edited by

          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

          Certified Specialist & Qt Ambassador <a href="http://www.crochik.com">Maemo, Meego, Symbian, Playbook, RaspberryPi, Desktop... Qt everywhere!</a>

          1 Reply Last reply Reply Quote 0
          • C
            changli85 last edited by

            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>’:

            1 Reply Last reply Reply Quote 0
            • C
              changli85 last edited by

              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>’:

              1 Reply Last reply Reply Quote 0
              • G
                giesbert last edited by

                Hi changli85,

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

                Nokia Certified Qt Specialist.
                Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

                1 Reply Last reply Reply Quote 0
                • V
                  vsorokin last edited by

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

                  --
                  Vasiliy

                  1 Reply Last reply Reply Quote 0
                  • C
                    changli85 last edited by

                    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

                    1 Reply Last reply Reply Quote 1
                    • D
                      DenisKormalev last edited by

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

                      1 Reply Last reply Reply Quote 0
                      • C
                        changli85 last edited by

                        Denis Kormalev , Thanks,I have solved this problem.

                        1 Reply Last reply Reply Quote 0
                        • First post
                          Last post