Results 1 to 7 of 7

Thread: include

  1. #1
    Join Date
    Jan 2006
    Posts
    976
    Thanks
    53
    Qt products
    Qt3
    Platforms
    Windows

    Default include

    Hi, I have seen this line at the end of a main.cpp. What does this do? Thanks

    Qt Code:
    1. //main.cpp
    2. .........
    3. #include "main.moc"
    To copy to clipboard, switch view to plain text mode 
    Regards

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: include

    It tells qmake to run moc on this file and generate "main.moc" with implementation of the signals and slots mechanism. You must use it when you place class definition with Q_OBJECT macro in a .cpp file.

  3. #3
    Join Date
    Jan 2006
    Posts
    976
    Thanks
    53
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: include

    sorrry, but when do I need to put a class in main.ccp instead of in a apart file? thanks
    Regards

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: include

    Quote Originally Posted by mickey
    sorrry, but when do I need to put a class in main.ccp instead of in a apart file? thanks
    You put class definitions in .cpp file only when you don't want them to be visible outside that file.

  5. #5
    Join Date
    Jan 2006
    Posts
    976
    Thanks
    53
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: include

    but Is there a pratical reason to hide a class into a .cpp? Why to hide?
    Thanks
    Regards

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: include

    Quote Originally Posted by mickey
    but Is there a pratical reason to hide a class into a .cpp? Why to hide?
    For example when you are writing a library, you might want to hide the implementation, so that after every change you don't have to recompile all programs that use that library. Ask google about "pimpl" or "d pointer".

  7. The following user says thank you to jacek for this useful post:

    mickey (4th April 2006)

  8. #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: include

    Or when you are lazy and don't want to create three files instead of one.

Similar Threads

  1. QApplication: no such file or directory
    By jochen_r in forum Newbie
    Replies: 13
    Last Post: 15th November 2008, 21:46
  2. Error: Using Multiple files
    By 3nc31 in forum Qt Programming
    Replies: 1
    Last Post: 22nd November 2007, 09:23
  3. Painting problem
    By Mel in forum Qt Programming
    Replies: 10
    Last Post: 8th May 2007, 21:38
  4. Can't create an object : initialisation problem ?
    By Nyphel in forum Qt Programming
    Replies: 5
    Last Post: 12th March 2007, 09:07
  5. use button from another Window
    By raphaelf in forum Qt Programming
    Replies: 11
    Last Post: 2nd March 2006, 20:31

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.