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 that inherits from QObject

template class that inherits from QObject

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 3 Posters 6.6k 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.
  • canellasC Offline
    canellasC Offline
    canellas
    wrote on last edited by
    #1

    Hi,

    I wrote this class

    template <typename t_figure>
    class drawing : public QObject, public t_figure  {
         Q_OBJECT
    ...
    

    And when I try to compile it, I get :

    mainwindow.o:-1: error: referência indefinida para `drawing<QGraphicsRectItem>::metaObject() const'
    

    Where "referência indefinida" means "undefined reference".

    Can I create such a class in Qt?

    Thanks

    raven-worxR 1 Reply Last reply
    0
    • canellasC canellas

      Hi,

      I wrote this class

      template <typename t_figure>
      class drawing : public QObject, public t_figure  {
           Q_OBJECT
      ...
      

      And when I try to compile it, I get :

      mainwindow.o:-1: error: referência indefinida para `drawing<QGraphicsRectItem>::metaObject() const'
      

      Where "referência indefinida" means "undefined reference".

      Can I create such a class in Qt?

      Thanks

      raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      @canellas
      AFAIK Q_OBJECT macro can't be used in templated classes.

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      3
      • sierdzioS Offline
        sierdzioS Offline
        sierdzio
        Moderators
        wrote on last edited by
        #3

        Indeed. QObjects classes cannot be templated. There are some workarounds for that (example), or you can use Qt modifications (Woboq's moc-less Qt or Coperspice) where it is allowed.

        (Z(:^

        1 Reply Last reply
        3
        • canellasC Offline
          canellasC Offline
          canellas
          wrote on last edited by
          #4

          Thanks all for your contribution

          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