Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Template class not supported by Q_OBJECT
Forum Updated to NodeBB v4.3 + New Features

Template class not supported by Q_OBJECT

Scheduled Pinned Locked Moved General and Desktop
9 Posts 4 Posters 26.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.
  • A Offline
    A Offline
    aekam
    wrote on 2 Feb 2012, 13:29 last edited by
    #1

    @
    // -- header file -------------------------------------------
    #ifndef MY_CLASS_C_H
    #define MY_CLASS_C_H

    #include <QObject>

    template <typename MY_TYPE>
    class MY_CLASS_c : public QObject
    {
    Q_OBJECT

    public:
    explicit MY_CLASS_c(QObject *parent = 0);

    signals:

    public slots:

    };

    #endif // MY_CLASS_C_H

    // -- source file --------------------------------------------
    #include "my_class_c.h"

    template <typename MY_TYPE>
    MY_CLASS_c <MY_TYPE>::MY_CLASS_c(QObject *parent) :
    QObject(parent)
    {
    }
    @

    @
    // -- compiler output ---------------------------------
    my_class_c.h:9: Error: Template classes not supported by Q_OBJECT
    @

    can anyone tell me where exactly i am making mistake.???

    [Edit] Please "use code wrapping tags ":http://developer.qt.nokia.com/wiki/ForumHelp#e3f82045ad0f480d3fb9e0ac2d58fb01

    If you take care of inches, you won't have to worry about miles... :)

    1 Reply Last reply
    0
    • K Offline
      K Offline
      koahnig
      wrote on 2 Feb 2012, 13:38 last edited by
      #2

      welcome to devnet

      You cannot combine templates and Q_OBJECT as the compiler output states.

      Vote the answer(s) that helped you to solve your issue(s)

      1 Reply Last reply
      0
      • A Offline
        A Offline
        aekam
        wrote on 2 Feb 2012, 13:45 last edited by
        #3

        I need to have signal-slot facility [Q_OBJECT] in a generic class [template]...
        any alternates.???

        If you take care of inches, you won't have to worry about miles... :)

        1 Reply Last reply
        0
        • A Offline
          A Offline
          aekam
          wrote on 2 Feb 2012, 14:02 last edited by
          #4

          one solution is to create two different classes, one for signal slot mechanism with Q_OBJECT and one with template which contains generic functionalities...

          then to inherit them...

          any thing else other than this.???

          If you take care of inches, you won't have to worry about miles... :)

          1 Reply Last reply
          0
          • A Offline
            A Offline
            andre
            wrote on 2 Feb 2012, 14:12 last edited by
            #5

            Nope, that's your only hope.
            The issue is that moc cannot handle templated code.

            1 Reply Last reply
            0
            • A Offline
              A Offline
              Asperamanca
              wrote on 2 Feb 2012, 15:43 last edited by
              #6

              As long as all you need to do is send and receive signals whose parameters are not of the templated type, the solution with a non-template base class, and a template derived class works well.

              1 Reply Last reply
              0
              • A Offline
                A Offline
                aekam
                wrote on 3 Feb 2012, 04:20 last edited by
                #7

                Ok, having base class with non template signal-slot functionality and to derive a template class from it, will work fine for me.

                but, just for knowledge, what if i need to have signal-slot with template type.???

                If you take care of inches, you won't have to worry about miles... :)

                1 Reply Last reply
                0
                • A Offline
                  A Offline
                  andre
                  wrote on 3 Feb 2012, 06:42 last edited by
                  #8

                  Then, you are out of luck. The only thing you can do then, is wrap the type in a QVariant and emit the signal or define the slot based on the QVariant from the baseclass again. Or, you don't emit the actual value, and let clients call a normal getter method in response to a changed signal instead of sending the value directly. You simply cannot define signals and slots in a template class.

                  1 Reply Last reply
                  0
                  • A Offline
                    A Offline
                    aekam
                    wrote on 3 Feb 2012, 07:29 last edited by
                    #9

                    hmm... then calling getter function in response to the signal seems pretty good...

                    If you take care of inches, you won't have to worry about miles... :)

                    1 Reply Last reply
                    0

                    1/9

                    2 Feb 2012, 13:29

                    • Login

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