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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:38:31+00:00 2026-05-27T10:38:31+00:00

My question is , can my interface inherit from QObject and how to do

  • 0

My question is , can my interface inherit from QObject and how to do that ? Well , i know that interfaces in C++ are simply classes that contains only virtual methods , and normally a class can inherit from a superclass. But if i do so i get an error due to ambiguous QObject references. I need to inherit QObject to add signals /slot feature to my plugins.

My interface

#ifndef LABELINTERFACE_H
#define LABELINTERFACE_H

#include <QLabel>
#include <QObject>

class LabelInterface : public QObject {

public :

    virtual ~LabelInterface() {}
    virtual QLabel* newLabel() = 0;

public slots:
    virtual void setLabelText() = 0;
};

Q_DECLARE_INTERFACE (LabelInterface,"com.stefan.Plugin.LabelInterface/1.0")

#endif // LABELINTERFACE_H

Plugin header file

#ifndef LABELPLUGIN_H
#define LABELPLUGIN_H

#include "labelinterface.h"

class LabelPlugin : public LabelInterface

{
    Q_OBJECT
    Q_INTERFACES(LabelInterface)

public:

    QLabel* label;
    QLabel* newLabel();
     LabelPlugin() {}
    ~LabelPlugin() {}

public slots:
    void setTextForLabel();
};

#endif // LABELPLUGIN_H

Implementation file

#include <QtGui>
#include "labelplugin.h"

QLabel* LabelPlugin::newLabel() {

    label = new QLabel("This plugin works");

    return label;
}

void LabelPlugin::setTextForLabel() {

    label->setText("This plugin works fine");

}

// Exporta plugin-ul
Q_EXPORT_PLUGIN2 (labelplugin,LabelPlugin)

I get error

labelplugin.cpp:18: error: cannot allocate an object of abstract type ‘LabelPlugin’
  • 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-27T10:38:31+00:00Added an answer on May 27, 2026 at 10:38 am

    You forgot to implement

    virtual void setLabelText() = 0;
    

    You implemented

    void setTextForLabel();
    

    was that a typo? To instantiate a class you need to override and implement all pure virtual methods in the base class. Since you’re not doing that, you class remains abstract.

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

Sidebar

Related Questions

I want to know if a class can inherit from a class and an
Can I specify interfaces when I declare a member? After thinking about this question
Question Can I build a image database/library that has an e-commerce style checkout system
this question can create a misunderstanding: I know I have to use CSS to
My question can be boiled down to, where does the string returned from stringstream.str().c_str()
I am trying to inherit following parameter in a java interface (an example from
I'm writing an interface that requires classes to implement a clone() method. My naive
First of all, I apologize for yet another interface question. I thought that this
I noticed that interface type definition metadata looks like: TypDefName: Interfaces.IMyInterface (02000003) Flags :
Simple question: Can a swing frame be completely modal ( block all others windows

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.