Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3432440
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T07:26:58+00:00 2026-05-18T07:26:58+00:00

In my application, I have the following class hierarchy: class Word { … }

  • 0

In my application, I have the following class hierarchy:

class Word
{
    ...
}

template <typename T> class Dictionary
{
    ...
};

class WordDictionary : public Dictionary<Word>
{
    Q_OBJECT

    ...
}

The WordDictionary class parses a dictionary which takes a long time. I am running the parsing function from within a separate thread and I want it to be able to signal the GUI thread from time to time to provide progress updates based on the current line number being parsed. That’s why I want it to be a Q_OBJECT. I tried to make the base class Dictionary a Q_OBJECT but got a message that Q_OBJECT templates are not supported. When I removed the macro, leaving only WordDictionary as Q_OBJECT, I get a bunch of error messages of the general form:

.\GeneratedFiles\Release\moc_dictionary.cpp(44) : error C2039: ‘staticMetaObject’ : is not a member of ‘Dictionary’
with
[
T=Word
]

Is there anything I can do to make my template-derived WordDictionary class a Q_OBJECT other than hardcoding the template functions inside it, producing a lot of boilerplate code?

edit: Changing the template declaration to:

template <typename T> class Dictionary : public QObject

made the code compile. I’m not sure if I’m not doing something stupid and if this will work correctly, though.

  • 1 1 Answer
  • 2 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T07:26:59+00:00Added an answer on May 18, 2026 at 7:26 am

    You can’t do this directly but there are usable work-rounds. See the article here.

    While it is theoretically possible for
    moc to handle templates, it would be
    extremely complex to implement, and
    would be highly impractical to use:
    For each template instantiation, moc
    would have to generate the appropriate
    meta-object code, and the generated
    code would have to be included once
    per link unit—which becomes a
    nightmare to maintain once a template
    class is used with the same template
    parameter in different compilation
    units.

    If the signals and slots don’t require
    the template parameter to be part of
    the prototype, the workaround is to
    make a template class inherit a
    QObject subclass that provides the
    required signals and slots. If
    signals and slots need to use the
    template parameters, the Observer
    pattern is an alternative.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In an ASP.NET MVC application where I have the following model.. public class EventViewModel
I have the following class as part of an asp.net application. public sealed class
I have the following class which is quite wide usely throughout my application :
I have following model class in my application: public class Dispute { public long
I have Window Application in VB.Net. I have following Classes & Enum. Public Class
I have the following class in a Seam 2 application, which is used in
Suppose I have the following class template: template<typename T> struct Wrapper { T* t_;
I have following models setup in my Django application class School(models.Model): name = models.TextField()
I have the following class: public class Movie { string Name get; set; string
I have the following class: public class DocketType : Enumeration<DocketType, int, string> { public

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.