Results 1 to 2 of 2

Thread: Bad design decision in Designer

  1. #1
    Join Date
    Jan 2011
    Location
    Boston, MA USA
    Posts
    9
    Qt products
    Qt4
    Platforms
    Windows

    Default Bad design decision in Designer

    I am new to QT and just want to bring your attention to one minor feature of designer which caused a lot of confusion and lost time for me. I have a button btnConnect on the form and wanted to create a custom slot for clicked() signal. Designer added the following code to the generated .h file:
    ...
    QObject::connect(btnConnect, SIGNAL(clicked()), MyProjectQtClass, SLOT(btnConnect_Clicked()));
    ...

    My next step should be to add the slot for appropriate class. When I searched for "MyProjectQtClass", I found the line on the bottom of the same generated .h file:

    namespace Ui {
    class MyProjectQtClass: public Ui_MyProjectQtClass {};

    I could not add any functions to that class because its definition was a part of compiler-generated header! It took me a while before I realized that this is pure coincidence and these are two different classes. "MyProjectQtClass" in the connect() call is in fact a parameter to the setupUi() function and "MyProjectQtClass" declared at the end of generated header is unrelated to it.

    I think it was a bad decision for Designer programmers to use the same spelling for two unrelated items. It can be very easily fixed in the future.

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Bad design decision in Designer

    The problem is not with designer, but with you misunderstanding how things work.
    I could not add any functions to that class because its definition was a part of compiler-generated header!
    You are not supposed to!
    At least, not in the generated header - for the very reason, that it is auto generated, and should you change something in the ui file, any chanes you made in the generated header will be lost.
    The correct way to use the generated class is through inheritance.
    It took me a while before I realized that this is pure coincidence and these are two different classes.
    There are no coincidences here - and these are not two different classes - but pointers to objects!
    The name you put in the "objectName" field is the name the VARIABLE of the class will have, and that is also what connect is using.

    Be sure to read and understand this here (it might save you some confusion and time in the future )
    http://doc.trolltech.com/4.7/designer-manual.html
    and specifically this:
    http://doc.trolltech.com/4.7/designe...tion-mode.html
    and this, for using your designer forms in your application (adding slots etc):
    http://doc.trolltech.com/4.7/designe...a-ui-file.html
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

Similar Threads

  1. Replies: 0
    Last Post: 28th October 2010, 13:24
  2. computer crash with Qt Design/ Qt Creator Designer
    By OverTheOCean in forum Qt Tools
    Replies: 1
    Last Post: 26th September 2009, 16:23
  3. Replies: 3
    Last Post: 5th October 2008, 23:41
  4. Need some advice for design decision
    By BeS in forum Qt Programming
    Replies: 2
    Last Post: 28th March 2006, 23:06

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.