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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T23:18:07+00:00 2026-05-30T23:18:07+00:00

class A { pointer* p; template<class T> f(T a) { p->property()->doSomething(a); // doSomething is

  • 0
class A
{
  pointer* p;
  template<class T> f(T a)
  {
    p->property()->doSomething(a); // doSomething is a template function
  }
};

Above won’t compile, but I want to access the member pointer in the template function even though it’s unsafe. The reason I want to do this is because ‘p->property()->doSomething(a)’ is actually really really long, and I’m tried of rewriting it (and I don’t want to use #define). So, how do I do something like that?

Edit: doSomething is a 3rd party function… but I think it is something like this:

template<class T>
void doSomething(T a)
{
  // something
}

Edit: here’s the actual code:

#include <QMainWindow>
#include <QtNetwork>
#include <QtWebKit>

namespace Ui {
class MainWindow;
}

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();

private slots:
    void replyFinished(QNetworkReply*);


private:
    Ui::MainWindow *ui;
    QNetworkAccessManager *nam;
    QUrl _url;

    void outputHeader(QNetworkReply*);

    template<class T> void writeToOuput(T arg)
    {
        ui->textEdit->append(QString("%1").arg(arg));
    }
};

Edit: Here’s the error I’m getting: ‘invalid use of incomplete type ui::MainWindow’
When I click it, it goes to this line ‘ui->textEdit->append(QString(“%1”).arg(arg));’ in the code

Edit: Here’s the other error: ‘Forward declaration of Ui::MainWindow’
When I click it, it goes no where.

  • 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-30T23:18:08+00:00Added an answer on May 30, 2026 at 11:18 pm

    With the way the question is worded as is right now, I’m really having trouble making out what the problem is. However, if this is the code giving you trouble:

    template<class T> void writeToOuput(T arg)
    {
        ui->textEdit->append(QString("%1").arg(arg));
    }
    
    1. Try including <QTextEdit>
    2. Does Ui::MainWindow actually define a member called textEdit?

    It’d help if you could post the build error.

    And finally, just a suggestion, but I’d recommend moving this to your cpp file as a non-member function:

    template<class T> void writeToOuput(Ui::MainWindow* ui, T arg)
    {
        ui->textEdit->append(QString("%1").arg(arg));
    }
    

    Rationale:

    1. Less compile-time dependencies, faster builds.
    2. Decouples the logic from your class as it does not need to be a member to function correctly.

    Update: op posted the error.

    Edit: Here’s the error I’m getting: ‘invalid use of incomplete type
    ui::MainWindow’

    You need to include the header that defines ui::MainWindow instead of just working with a forward declaration. For MOC-generated files like this, that’s generally going to be called ui_MainWindow.h.

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

Sidebar

Related Questions

I know that the normal member function of a template class will be instantiated
In my template smart pointer class, I want to have separate constructors and assignment
In my attempt to develope a thread-safe C++ weak pointer template class, I need
I have the following code: template <class T> struct pointer { operator pointer<const T>()
I want to know the runtime type of a base class pointer, I know
Modern ATL/MFC applications now have access to a new shared pointer class called CAutoPtr,
i need a Function Pointer from a base class. Here is the code: class
I'm trying to set a static pointer variable in a class but I'm getting
I have a C++ template class that contains a method pointer and a class
I have a subset of a pointer class that look like: template <typename T>

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.