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. How to build real template class?

How to build real template class?

Scheduled Pinned Locked Moved Unsolved General and Desktop
26 Posts 11 Posters 2.2k Views
  • 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
    Anonymous_Banned275
    wrote on 5 May 2024, 18:16 last edited by Anonymous_Banned275 5 May 2024, 18:39
    #1

    Using Qt to build C++ class I end up with this (fake) "template class" declaration.
    That is what Qt dementation calls it -template class .

    Is there a way I can build REAL template class using Qt?

    ADDENDUM
    It is KISS - just add template <typename T> as type, BUT
    then Q_OBJECT is "not supported" !

    which brings up another question
    if ALL Qt "classes" inherit from QObject anyway

    so what does placing Q_OBJECT (insert its name here )
    do anyway?

    Looks as I poked stick into hornets nest - all kinds of "stuff" I took for granted so far.

    // cut an paste hack
    
    template <typename T> class TEST_Template_Hack : public QObject
    {
        Q_OBJECT
    public:
        explicit TEST_Template_Hack(QObject *parent = nullptr);
    
    signals:
    
    };
    
    #ifndef TEST_TEMPLATE_H
    #define TEST_TEMPLATE_H
    
    #include <QObject>
    
    class TEST_Template : public QObject
    {
        Q_OBJECT
    public:
        explicit TEST_Template(QObject *parent = nullptr);
    
    signals:
    
    };
    
    #endif // TEST_TEMPLATE_H
    
    1 Reply Last reply
    0
    • A Offline
      A Offline
      Axel Spoerl
      Moderators
      wrote on 5 May 2024, 19:18 last edited by
      #2

      @AnneRanch
      A template class is correct if it compiles, and wrong if it doesn't.
      A class is either a template class, or it's not.
      I don't understand what you mean by "fake" and "real".

      The only limitation in Qt is that you can't use Q_OBJECT in a template class.
      But the template class can inherit from a class, that does have the Q_OBJECT macro.

      #include <QObject>
      
      class TEST : public QObject
      {
          Q_OBJECT
      public:
          explicit TEST_Template(QObject *parent = nullptr);
      
      signals:
          void aSignal(int number);
      };
      
      template <typename T>
      class TEST_Template : public TEST
      {
          ...
      };
      

      Looks as I poked stick into hornets nest - all kinds of "stuff" I took for granted so far.

      Don't worry, no hornets in this neighbourhood.

      Software Engineer
      The Qt Company, Oslo

      1 Reply Last reply
      1
      • A Offline
        A Offline
        Asperamanca
        wrote on 6 May 2024, 10:21 last edited by
        #3

        The important question is: What are you trying to achieve?
        I struggle to see a compelling use case for a templated QObject, but I might be missing something...

        1 Reply Last reply
        2
        • A Offline
          A Offline
          Anonymous_Banned275
          wrote on 6 May 2024, 12:45 last edited by
          #4

          I do not agree with your opinion : What are you trying to achieve?
          My missed point is - Qt documentation call the result of their process of building a class a " template". It is NOT template TYPE by definition, it is Qt miss use of a term.
          I have no illusion that pointing that out will "achieve " anything. Qt is pushing its own terminology and continue to do so irregardless of me , a user , opinion. They are the experts , in their opinions / view.
          My only "achievement' could be to make others users of Qt aware. That is about all I could hope for.

          A 1 Reply Last reply 6 May 2024, 19:11
          0
          • C Offline
            C Offline
            Christian Ehrlicher
            Lifetime Qt Champion
            wrote on 6 May 2024, 13:00 last edited by
            #5

            It is creating a template for a class derived from QObject, not a template class. You are mixing different stuff.

            Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
            Visit the Qt Academy at https://academy.qt.io/catalog

            1 Reply Last reply
            4
            • A Offline
              A Offline
              Asperamanca
              wrote on 6 May 2024, 13:01 last edited by
              #6

              Could you link the relevant documentation page?

              1 Reply Last reply
              0
              • A Offline
                A Offline
                Anonymous_Banned275
                wrote on 6 May 2024, 14:22 last edited by
                #7

                https://wiki.qt.io/Qt_for_Beginners

                F 1 Reply Last reply 11 May 2024, 23:57
                0
                • A Offline
                  A Offline
                  Asperamanca
                  wrote on 6 May 2024, 14:31 last edited by
                  #8

                  "Template" in this context is simply an English word in the same way as you may have a "Template for a presentation", i.e. something generic to help you get started, from which you can then customize what you want.

                  1 Reply Last reply
                  7
                  • A Offline
                    A Offline
                    Anonymous_Banned275
                    wrote on 6 May 2024, 15:15 last edited by
                    #9

                    I disagree , especially when it is " for beginners" .
                    Cheers

                    A 1 Reply Last reply 7 May 2024, 07:46
                    0
                    • A Anonymous_Banned275
                      6 May 2024, 12:45

                      I do not agree with your opinion : What are you trying to achieve?
                      My missed point is - Qt documentation call the result of their process of building a class a " template". It is NOT template TYPE by definition, it is Qt miss use of a term.
                      I have no illusion that pointing that out will "achieve " anything. Qt is pushing its own terminology and continue to do so irregardless of me , a user , opinion. They are the experts , in their opinions / view.
                      My only "achievement' could be to make others users of Qt aware. That is about all I could hope for.

                      A Offline
                      A Offline
                      Axel Spoerl
                      Moderators
                      wrote on 6 May 2024, 19:11 last edited by
                      #10

                      It is NOT template TYPE by definition, it is Qt miss use of a term.

                      That's simply wrong, @AnneRanch.
                      The misunderstanding is entirely on your side.

                      As @Asperamanca indicated, the term "template" is standard English vocabulary. If you reserve it exclusively for what is a template in C++, you limit your own vocabulary.

                      The documentation page you referred, is truly outdated, but it doesn't contain anything wrong. It uses word "template" in two different contexts:

                      • TEMPLATE directive of qmake
                      • creating a class definition, following a template (as @Asperamanca already explained)

                      The page does not contain any mention of the term "template" in C++ code. That makes the context pretty obvious for any C++ programmer, beginners included.

                      Software Engineer
                      The Qt Company, Oslo

                      1 Reply Last reply
                      4
                      • A Anonymous_Banned275
                        6 May 2024, 15:15

                        I disagree , especially when it is " for beginners" .
                        Cheers

                        A Offline
                        A Offline
                        Asperamanca
                        wrote on 7 May 2024, 07:46 last edited by
                        #11

                        @AnneRanch said in How to build real template class?:

                        I disagree , especially when it is " for beginners" .
                        Cheers

                        I agree that the conflict of terms here is a bit unfortunate. Then again, I cannot come up with a more fitting term for "template" in this context. If you have a better idea, you can also write documentation suggestion to bugreports.qt.io

                        P 1 Reply Last reply 7 May 2024, 09:30
                        2
                        • A Asperamanca
                          7 May 2024, 07:46

                          @AnneRanch said in How to build real template class?:

                          I disagree , especially when it is " for beginners" .
                          Cheers

                          I agree that the conflict of terms here is a bit unfortunate. Then again, I cannot come up with a more fitting term for "template" in this context. If you have a better idea, you can also write documentation suggestion to bugreports.qt.io

                          P Offline
                          P Offline
                          Pl45m4
                          wrote on 7 May 2024, 09:30 last edited by
                          #12

                          @Asperamanca said in How to build real template class?:

                          I cannot come up with a more fitting term for "template" in this context

                          I can think of another term (don't know if better or not), but I'm not allowed to comment :)))
                          The first part is a color, the second part of the word is what a certain I/O device does :)))


                          If debugging is the process of removing software bugs, then programming must be the process of putting them in.

                          ~E. W. Dijkstra

                          R 1 Reply Last reply 7 May 2024, 12:15
                          0
                          • P Pl45m4
                            7 May 2024, 09:30

                            @Asperamanca said in How to build real template class?:

                            I cannot come up with a more fitting term for "template" in this context

                            I can think of another term (don't know if better or not), but I'm not allowed to comment :)))
                            The first part is a color, the second part of the word is what a certain I/O device does :)))

                            R Offline
                            R Offline
                            Redman
                            wrote on 7 May 2024, 12:15 last edited by
                            #13

                            @Pl45m4 yellow fax

                            P A 2 Replies Last reply 7 May 2024, 12:25
                            1
                            • R Redman
                              7 May 2024, 12:15

                              @Pl45m4 yellow fax

                              P Offline
                              P Offline
                              Pl45m4
                              wrote on 7 May 2024, 12:25 last edited by
                              #14

                              @Redman said in How to build real template class?:

                              yellow fax

                              Yep. That's it :))
                              You're good :D


                              If debugging is the process of removing software bugs, then programming must be the process of putting them in.

                              ~E. W. Dijkstra

                              1 Reply Last reply
                              0
                              • R Redman
                                7 May 2024, 12:15

                                @Pl45m4 yellow fax

                                A Offline
                                A Offline
                                Axel Spoerl
                                Moderators
                                wrote on 7 May 2024, 12:26 last edited by
                                #15

                                @Redman
                                C'mon, ever seen a yellow fax?
                                He meant orange jam, obviously.

                                Software Engineer
                                The Qt Company, Oslo

                                P 1 Reply Last reply 7 May 2024, 13:03
                                1
                                • A Axel Spoerl
                                  7 May 2024, 12:26

                                  @Redman
                                  C'mon, ever seen a yellow fax?
                                  He meant orange jam, obviously.

                                  P Offline
                                  P Offline
                                  Pl45m4
                                  wrote on 7 May 2024, 13:03 last edited by
                                  #16

                                  @Axel-Spoerl said in How to build real template class?:

                                  He meant orange jam, obviously.

                                  Actually I was referring to commonly used term "reddisplay".
                                  ... but I agreed to @Redman so he wouldn't feel bad :)))


                                  If debugging is the process of removing software bugs, then programming must be the process of putting them in.

                                  ~E. W. Dijkstra

                                  1 Reply Last reply
                                  2
                                  • jsulmJ Offline
                                    jsulmJ Offline
                                    jsulm
                                    Lifetime Qt Champion
                                    wrote on 7 May 2024, 13:28 last edited by
                                    #17

                                    bluescreen :-)

                                    https://forum.qt.io/topic/113070/qt-code-of-conduct

                                    P 1 Reply Last reply 7 May 2024, 14:14
                                    3
                                    • jsulmJ jsulm
                                      7 May 2024, 13:28

                                      bluescreen :-)

                                      P Offline
                                      P Offline
                                      Pl45m4
                                      wrote on 7 May 2024, 14:14 last edited by
                                      #18

                                      @jsulm said in How to build real template class?:

                                      bluescreen :-)

                                      That's what you get when using yellow fax wrong :))


                                      If debugging is the process of removing software bugs, then programming must be the process of putting them in.

                                      ~E. W. Dijkstra

                                      1 Reply Last reply
                                      1
                                      • A Offline
                                        A Offline
                                        Axel Spoerl
                                        Moderators
                                        wrote on 7 May 2024, 19:41 last edited by Axel Spoerl 5 Jul 2024, 19:49
                                        #19

                                        I got it: Black Label!
                                        Edit: Green Card.

                                        Software Engineer
                                        The Qt Company, Oslo

                                        1 Reply Last reply
                                        0
                                        • J.HilkJ Online
                                          J.HilkJ Online
                                          J.Hilk
                                          Moderators
                                          wrote on 8 May 2024, 07:10 last edited by
                                          #20

                                          This took me exceedingly long to get omfg.


                                          Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                                          Q: What's that?
                                          A: It's blue light.
                                          Q: What does it do?
                                          A: It turns blue.

                                          1 Reply Last reply
                                          0

                                          7/26

                                          6 May 2024, 14:22

                                          19 unread
                                          • Login

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