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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T15:02:28+00:00 2026-05-25T15:02:28+00:00

Learning QT (with C++), I have been defining my own classes, which are not

  • 0

Learning QT (with C++), I have been defining my own classes, which are not QObjects derivates. Even if QT tutorial teach you to extend their widgets in order to make your own I don’t because I was thinking that my code would be more “portable” and less QT inherent (if that makes sense) in case I switched to another graphical toolkit.

So my classes are something like this.-

class mainWindow
{
    QVBoxLayout *winLayout;
    public:
        QWidget *winWidget;
        mainWindow();
}

…so, having the main widget as a public member and everything being operated from within the classes, adding methods to manipulate my widgets.

In case I need Signals and Slots, I make a class extending QObject and use the Q_OBJECT macro.

But now I wonder, is my notion (explained in the beginning) even vaguely right? Do you think that I can face any issues in the future by doing this my way and not extending QT own widgets? What method should I stick to?

  • 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-25T15:02:28+00:00Added an answer on May 25, 2026 at 3:02 pm

    Your clas is not a proper QWidget, but I don’t think it would be a problem to Qt. Unless you need to gain acces to some protected elements of wigets (eg. interact with events) you could go without ever inheriting qt widgets – the choice of design is yours.

    The only reason for inheriting might be to save some memory taken by additional QObject, but if your class is not extensivly used in application, this should not be an issue.

    About being less “Qt inherent” i can only say that moving application from one framework to another usually needs lots of changes, independently on your design, so this aregument doesn’t really convince me.

    On tth other hand this is generally bad idea to keep public field in a class like this – accidental modifications will cause difficult to track errors – think about making winWidget private and adding some accesor method perhaps?

    When i was beggining to learn qt, I also had aversion to subclassing QWidgets, but soon i realised that it is simply more comfortable to inherit, mostly because you don’t need heavy changes to your class if one day you need event-interaction.

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

Sidebar

Related Questions

I have been learning RESTful webservices following this tutorial http://www.vogella.de/articles/REST/article.html . As I understand,
I have been learning Java and have had no problem with projects in which
I'm not a very experience programmer and have been learning HTML/CSS/JS on the fly.
I have been learning Objective C on my own for some time already and
I have been learning about the basics of C# but haven't come across a
I have been learning C++ for three months now and in that time created
I have been learning more and more javascript; it's a necessity at my job.
I have been learning to use Emacs for a little while now. So far
I have been learning C++ with some books from school that are from the
I have been learning Hibernate for the past few weeks, I have gotten most

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.