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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T11:15:39+00:00 2026-05-31T11:15:39+00:00

When writting class TemplateHandler, say I use TemplateHandler.h (for my the header) and TemplateHandler.cpp

  • 0

When writting class TemplateHandler, say I use TemplateHandler.h (for my the header) and TemplateHandler.cpp (for the declarations). Like

// Templatehandler.h

#ifndef TEMPLATEHANDLER_H
#define TEMPLATEHANDLER_H

#include <QObject>   // Forward declaration of QObject generates error

class QListView;     // Forward declarations
class QTextEdit;
class QModelIndex;
class QStringListModel;

class TemplateHandler : public QObject
{
  Q_OBJECT
  public:
    TemplateHandler(QListView *view, QTextEdit *textEdit, QObject *parent);
    virtual ~TemplateHandler();

  private:
    QTextEdit *mTextEdit;
    QStringListModel *mModel;
};

#endif

And the source

#include "templatehandler.h"
#include <QListView>             // Inclusion of lib
#include <QTextEdit>
#include <QObject>
#include <QStringListModel>

TemplateHandler::TemplateHandler(QListView *view, QTextEdit *textEdit, QObject *parent) : QObject(parent), mTextEdit(textEdit)
{
    mModel = new QStringListModel(this);
    QStringList templates;
    templates << "<html>" << "</html>" << "<body>" << "</body>";
    mModel->setStringList(templates);
    view->setModel(mModel);
    connect(view, SIGNAL(clicked(const QModelIndex&)), SLOT(insertText(const QModelIndex&)));
}

TemplateHandler::~TemplateHandler() {
    // TODO Auto-generated destructor stub
}

But in this case forward declaration of QObject generates error, however the rest are okey. I need some help on that.

  • 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-31T11:15:40+00:00Added an answer on May 31, 2026 at 11:15 am

    This is a pure c++ “issue”.

    Forward declarations only work when the compiler do not need the size of the class at the time the header is included. E.g. for pointers, even to class, it knows the size.

    On the other hand, for object created on the stack or for parent classes, it needs to know the exact size of the struct (e.g. sizeof(QObject)), which it can only get by including the .h.

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

Sidebar

Related Questions

I am currently writting programs in linux like this: From the command line I
I am writting a Python class with this constructor: #constuctor def __init__(self, initPt_=[1,1],fun_=Optim_tests.peaks,NITER_=30,alpha_=0.7,NMAX_=5000,FTOL_=10**(-10)): self.initPt
I am writting jnuit test case for testing API. my class is as follows
I'm writting a custom assembly to be referenced in a report. I'd like to
I'm writting a generalized method to use it in a special task at a
Original Question I am writting a logging class where the goal is to be
I am currently writting a JNI wrapper for a C++ class and I'm not
im writting an actionScript class to handle my web service calls. When i retrieve
I have the weirdest bug, when writting my LogHelper class. I am using org.osgi.service.log.LogService
I often find myself writing class constructors like this: class foo: def __init__(self, arg1,

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.