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
  • 0 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

We have a Hibernate/Spring application that have the following Spring beans: <bean id=transactionManager class=org.springframework.orm.hibernate3.HibernateTransactionManager
I have the following application which replicates an issue I'm having in a larger
I have read the following code: public class DalFactory { private static IDataContext _instance
I have an application web.xml with the following entry: <error-page> <error-code>404</error-code> <location>/system_files/error/p_notfound.jsp</location> </error-page> However,
I have an application that is made up of the following: A central database
I'm converting an application to use Java 1.5 and have found the following method:
I am working on a web application and I have run into the following
I have a C# application that includes the following code: string file = relativePath.txt;
I have a web application that comprises the following: A web project (with a
I have a simple application with the following code: FileInfo[] files = (new DirectoryInfo(initialDirectory)).GetFiles();

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.