Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Abstract type with qmlRegisterType
Forum Updated to NodeBB v4.3 + New Features

Abstract type with qmlRegisterType

Scheduled Pinned Locked Moved QML and Qt Quick
10 Posts 6 Posters 9.2k Views 1 Watching
  • 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 Offline
    C Offline
    cbrake
    wrote on last edited by
    #1

    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
    0
    • F Offline
      F Offline
      fcrochik
      wrote on last edited by
      #2

      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
      0
      • F Offline
        F Offline
        fcrochik
        wrote on last edited by
        #3

        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
        0
        • C Offline
          C Offline
          changli85
          wrote on last edited by
          #4

          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
          0
          • C Offline
            C Offline
            changli85
            wrote on last edited by
            #5

            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
            0
            • G Offline
              G Offline
              giesbert
              wrote on last edited by
              #6

              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
              0
              • V Offline
                V Offline
                vsorokin
                wrote on last edited by
                #7

                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
                0
                • C Offline
                  C Offline
                  changli85
                  wrote on last edited by
                  #8

                  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
                  1
                  • D Offline
                    D Offline
                    DenisKormalev
                    wrote on last edited by
                    #9

                    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
                    0
                    • C Offline
                      C Offline
                      changli85
                      wrote on last edited by
                      #10

                      Denis Kormalev , Thanks,I have solved this problem.

                      1 Reply Last reply
                      0

                      • Login

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved