+ Reply to Thread
Results 1 to 5 of 5

Thread: How to automatically create boilerplate slot code from Ui form object?? Possible??

  1. #1
    Join Date
    Apr 2017
    Posts
    18
    Qt products
    Qt5
    Platforms
    Windows

    Default How to automatically create boilerplate slot code from Ui form object?? Possible??

    Hi,

    Was wondering if I have a qSpinBox on a UI Form like QWidget or QMainwindow the general signal that is sent when a value is changed is: on_mySpinbox_valueChanged(int) but was wondering how can I get QT Designer or Creator to automatically generate the Slot code for me??

    Is this even possible? Just like when you <Alt>-<Enter> over a definition to generate the boilerplate code in the cpp file...


    Thanks

  2. #2
    Join Date
    Apr 2017
    Posts
    18
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: How to automatically create boilerplate slot code from Ui form object?? Possible?

    Figured it out - Right click go to slot..

  3. #3
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    3,697
    Thanks
    212
    Thanked 566 Times in 556 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: How to automatically create boilerplate slot code from Ui form object?? Possible?

    I think you will find as you get more experience with Qt that using Qt Designer to create and connect your slots for you leads to a lot of head-banging. When you use Qt Designer like this, not only does it create the slot code at design time, it also connects the signals and slots at run time.

    So now you have code that you are in control of (the connect() calls you make yourself) and code that does magic behind the scenes (the connect() calls made via setupUi() from the boilerplate code).

    I don't know how many times I have sat with the debugger and puzzled about "How in the heck is this slot being called? I haven't called connect() anywhere." Eventually I start looking in the UI file and find there is an implicit signal / slot connection I had forgotten all about.

    So now I don't allow Qt Designer to do any slot editing for me - all of it is done through explicit connect() calls in code -I- write. Yes, I have to type a few more lines, but I can see exactly what is happening with the UI and change it in one place.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  4. #4
    Join Date
    Apr 2017
    Posts
    18
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: How to automatically create boilerplate slot code from Ui form object?? Possible?

    So your saying its more efficient to hard code the connect signal and slot connections?

  5. #5
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    3,697
    Thanks
    212
    Thanked 566 Times in 556 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: How to automatically create boilerplate slot code from Ui form object?? Possible?

    So your saying its more efficient to hard code the connect signal and slot connections?
    Not necessarily. In one case you do a bunch of mouse clicks in Qt Designer, in the other you write a line of code.

    The point is that by using Qt Designer to create and connect your signals and slots you can't open your cpp file and see everything that is going on in the UI. Instead, if you've made connections using Qt Designer, you need to look there in the .ui file for those, and if you've also made other connect() calls in your own code (to non-GUI QObject-based classes, for example), you need to look in the .cpp file also.

    My preference is to make all connect() calls manually in the cpp file. I have everything in front of me where I can see it in one place and don't have to remember that some other connect calls occurred in a different place.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

+ Reply to Thread

Similar Threads

  1. Replies: 1
    Last Post: 28th February 2015, 16:20
  2. Replies: 11
    Last Post: 20th April 2011, 21:53
  3. How can we create .pc file automatically?
    By learning_qt in forum Qt Programming
    Replies: 6
    Last Post: 9th December 2010, 05:19
  4. automatically complete fields on the form
    By TomASS in forum General Programming
    Replies: 1
    Last Post: 13th July 2010, 19:14
  5. Replies: 1
    Last Post: 27th February 2010, 10:33

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