Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Where are the .ui files?
Forum Updated to NodeBB v4.3 + New Features

Where are the .ui files?

Scheduled Pinned Locked Moved Unsolved General and Desktop
21 Posts 8 Posters 1.5k Views 4 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S SimonSchroeder

    @Kent-Dorfman said in Where are the .ui files?:

    The transfer of object ownership in the parent child widget tree relies on it, and is why stack allocated QObjects are a bad idea.

    What I'm trying to say is that in C++ it is generally a good idea to put variables on the stack and not on the heap. And you are right that we need to be careful with Qt. Everything in Qt that has a parent assigned needs to be heap allocated (and not managed by a smart pointer!). However, the QApplication and the top-level widget don't have a parent assigned. This means that in a large application no widget will ever be destroyed because the parent (i.e. the MainWindow in my example) is never destroyed. That's why I advocate for the top-level widget to be on the stack. Otherwise, you should call app->exec(), store its return value, explicitely delete the top-level widget, and finally return the return value from app->exec(). Using a stack variable is much easier.

    I am so vocal about it because I was taught to use pointers and new everywhere when I started with C++. Turns out that this was the source of most bugs. So, using stack variables almost everywhere (except for Qt's objects with parents assigned) helps to prevent a lot of bugs. (There are other reasons to use pointers related to OOP and polymorphism, but even then there are fewer cases than I was taught initially.)

    Pl45m4P Offline
    Pl45m4P Offline
    Pl45m4
    wrote on last edited by Pl45m4
    #21

    @SimonSchroeder said in Where are the .ui files?:

    I am so vocal about it because I was taught to use pointers and new everywhere when I started with C++. Turns out that this was the source of most bugs. So, using stack variables almost everywhere (except for Qt's objects with parents assigned) helps to prevent a lot of bugs. (There are other reasons to use pointers related to OOP and polymorphism, but even then there are fewer cases than I was taught initially.)

    True. This correlates also with my experience.

    @Pl45m4 said in Where are the .ui files?:

    Have seen beginners creating everything, Qt and non-Qt related stuff, on the heap regardless... that could need some optimization :)

    Could be "bad" teachers, wrong guides or courses... or just the wrong assumptions that it needs to be done this way.
    People have heard "C++ is hard", "C++ is complicated", "Lots of bad black memory/pointer magic you can do"... which is kinda accurate... so they take the sledgehammer to crack a nut :D
    And maybe they get "inpired" by other OOP languages like Java, where you don't have to manage your memory yourself and new'ing something does not come with any drawback, therefore it's most used.


    If debugging is the process of removing software bugs, then programming must be the process of putting them in.

    ~E. W. Dijkstra

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved