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 8662561
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T16:45:48+00:00 2026-06-12T16:45:48+00:00

How can I create an interface class, something like this : template<typename file_system_t> class

  • 0

How can I create an interface class, something like this :

template<typename file_system_t>
    class ireciver_intervace : public QObject
    {
        public:
        typedef typename file_system_t::file_system_item file_system_item;
    public Q_SLOTS:
        virtual void dataChangeItem(file_system_item *item)=0;
        virtual void removeItem(file_system_item *item)=0;
        virtual void insertItem(file_system_item *item)=0;
    };

and derived class

class FileItemModel:public QAbstractItemModel ,public ireciver_intervace<file_system>
        {
            Q_OBJECT
        }

When I inherit from this class I get an error mentioning ambiguous conversions. I understand this is the right behavior of the compiler, but how can I get interfaces slots for my future classes? Maybe I must use the Q_DECLARE_INTERFACE macro?

  • 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-06-12T16:45:49+00:00Added an answer on June 12, 2026 at 4:45 pm

    QObject subclasses with signal/slot functionality can’t be templated.

    You can simply drop the QObject inheritance of your interface, the rest will be fine. It’s no problem to define a (pure) virtual function and then (in the subclass) make a slot out of it by putting it in the slots section of your subclass:

    template<typename file_system_t>
    class ireceiver_interface
    {
    public:
        typedef typename file_system_t::file_system_item file_system_item;
    
        // pure virtual functions (NO SLOTS!):
        virtual void dataChangeItem(file_system_item *item)=0;
        virtual void removeItem(file_system_item *item)=0;
        virtual void insertItem(file_system_item *item)=0;
    };
    

    class FileItemModel: public QAbstractItemModel,
                         public ireceiver_interface<file_system_t>
    {
        Q_OBJECT
        ...
    public slots:
        // implementations (slots):
        virtual void dataChangeItem(file_system_item *item);
        virtual void removeItem(file_system_item *item);
        virtual void insertItem(file_system_item *item);
        ...
    }
    

    However, the idea of an interface is to define what functions a concrete class has to implement. Here, the interface can’t force the subclass to define those functions as slots, it can also define them as non-slot functions. This minor problem can’t be solved. Even if the interface could be a QObject, the subclass could then decide to re-implement those methods as non-slots!

    Note that you have two typos in your class name: It’s receiver, not reciver and it’s interface, not intervace.

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

Sidebar

Related Questions

When we create interface methods, can't we do something like in java : void
I have a generic interface for a mathematics library, something like this: [ContractClass(typeof(MathsDoubleContracts))] public
I'd like to create a template interface for data-handling classes in my projects. I
I have an abstract base class called WidgetBase which looks like this: public abstract
If I create the CButton in the myTab class, I can't interact with it
I'm looking to create an interface where the user can navigate through large volumes
I want to create search interface to search data from GAE datastore? Can i
When I create UITextField inside Interface Builder, I can access Events tab for it,
I'm looking for a user interface language to create an application that can be
In C++, you can do the following: class base_class { public: virtual void do_something()

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.