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

  • Home
  • SEARCH
  • 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 1104327
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T01:28:04+00:00 2026-05-17T01:28:04+00:00

I’m trying to collect an often used subset of GUI-Elements together into one Subclass,

  • 0

I’m trying to collect an often used subset of GUI-Elements together into one Subclass, which can be “included” into the real GUIs later without rewriting the given functionality (don’t ask why, I wanna learn it for later use). The Subclass should use it’s own *.ui-File and should be put into an QWidget resding in the real GUI. After this, it would be nice to access some methods of the Subclass from the real GUI — like the state of a button or so.

But how do I do this right?

In the moment, my Subclass works and is instantiated in main, but cannot be accessed from the real GUI because its only declared in main.

My Subclass Header-File:

class logger : public QWidget, private Ui::loggerWidget {
    Q_OBJECT

public:
    logger(QWidget *parent = 0);
    virtual ~logger();
    // some more stuff...
}

The corresponding constructor. I had to run setupUI with “parent” instead of “this”, but I’m not sure that this is correct — anyways, it works… otherwise, the subelements from the subclass are not shown in the main-window of the real GUI.

logger::logger(QWidget *parent) : QWidget(parent){
    setupUi(parent);
    //ctor
}

Inside the main.cpp the main-window is constructed, which uses it’s own *.ui-File (containing one widget “widget_loggerArea”) aswell. Doing so, I can not access methods of “logger” from within “loggerTest”:

int main(int argc, char *argv[])
{
    QApplication app(argc, argv);

    loggerTest window;

    logger myLog(window.widget_loggerArea);

    window.show();

    return app.exec();
}

I can’t put the constructor of “logger” into the constructor of the main-window “loggerTest”, since it will be destroyed immidiately and never enters the event-loop.

I’m sure I’m missing some concept of object-oriented programming, or the way qt handles its stuff… I would be gratefull if someone could put my nose to this 😉


I was so stupid… using a pointer with new and delete does the job… this is so silly, I can’t believe it! I’m more used to VHDL recently, this weakens my C++-karma…

  • 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-17T01:28:04+00:00Added an answer on May 17, 2026 at 1:28 am

    So, the answer is in the real GUI class. The Constructor:

    testLogger::testLogger(QMainWindow *parent) : QMainWindow(parent){
        setupUi(this);
    
        myLog = new logger(widget_loggerArea);
    }
    

    In main.cpp:

    QApplication app(argc, argv);
    testLogger window;
    window.show();
    

    And in constructor of logger, setupUi works with “this”:

    dfkiLogger::dfkiLogger(QWidget *parent) : QWidget(parent){
        setupUi(this);
    }
    

    Yes, thats it… Just for completebility, maybe someone needs a similar “push in the right direction”…

    EDIT: In the header of the SubClass the scope of the ui-Elements has to be updated to “public”, too:

    class logger : public QWidget, public Ui::loggerWidget {
        Q_OBJECT
    
        public:
            logger(QWidget *parent = 0);
            virtual ~logger();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm trying to select an H1 element which is the second-child in its group
Basically, what I'm trying to create is a page of div tags, each has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
this is what i have right now Drawing an RSS feed into the php,
I am trying to render a haml file in a javascript response like so:
I have a French site that I want to parse, but am running into

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.