Results 1 to 8 of 8

Thread: Pushbutton slot is in header not cpp

  1. #1
    Join Date
    Feb 2013
    Posts
    71
    Thanks
    7
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Pushbutton slot is in header not cpp

    All of a sudden when I add a button and do go to slot, the declaration and function for the slot is added in the .h header file and the function is not called. I have several ui forms where the slot is declared in .h and function for the slot is created in the cpp.

    I've tried renaming the button, deleted and created a new one but it still creates the function in the header file alone. Manually writing the slot in the cpp doesn't work either, the program doesn't even compile it, it just closes when I click the button.

    Thanks in advance for the help

    EDIT: Manually writing the function in .cpp does work but I would still like to know why qt creates the function in .h header rather than .cpp source code.
    Last edited by Cyrebo; 27th April 2013 at 12:46.

  2. #2
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Pushbutton slot is in header not cpp

    All of a sudden when I add a button and do go to slot
    What?

    the declaration and function for the slot is added in the .h header file
    Ok.

    and the function is not called.
    What? Do you have an IDE problem or a run-time problem? Try to keep threads related to only one issue otherwise things get too difficult to follow.
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Pushbutton slot is in header not cpp

    If you have problems with QtCreator, please post them in Qt Tools forum.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  4. #4
    Join Date
    Feb 2013
    Posts
    71
    Thanks
    7
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Pushbutton slot is in header not cpp

    As in the function should be created in .cpp? What do you find difficult to follow?

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Pushbutton slot is in header not cpp

    It is not true that the method should be created in a cpp file, c++ allows methods implemented inline in the class definition.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  6. #6
    Join Date
    Feb 2013
    Posts
    71
    Thanks
    7
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Pushbutton slot is in header not cpp

    Quote Originally Posted by wysota View Post
    It is not true that the method should be created in a cpp file, c++ allows methods implemented inline in the class definition.
    But why change now? Your right it doesn't have to but it usually does which is the correct way to do it. I haven't changed compiler or anything.

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Pushbutton slot is in header not cpp

    The compiler has nothing to do with it. If Creator didn't detect you had an implementation file associated with the header file then it created a method body for you in the header file. You can freely move it to the implementation file if you want. And it's not true that it is more "correct" to put method bodies in implementation files. It really depends on the context.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  8. #8
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Pushbutton slot is in header not cpp

    In general, I would advise against using the go-to-slot functionality because it uses the auto connection features based on object names and that can easily get out of sync when editing the designer file.

    Cheers,
    _

Similar Threads

  1. Generated UI header incorrectly includes class header?
    By droneone in forum Qt Programming
    Replies: 7
    Last Post: 14th June 2012, 14:48
  2. Replies: 3
    Last Post: 29th April 2011, 08:54
  3. Replies: 18
    Last Post: 25th January 2010, 11:23
  4. QStandardItem's header item and header label
    By feverzsj in forum Newbie
    Replies: 1
    Last Post: 14th January 2010, 19:57
  5. How to customize horizontal header (diagonal header view)
    By vairamuthu.g in forum Qt Programming
    Replies: 4
    Last Post: 4th September 2008, 15:59

Tags for this Thread

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.