Results 1 to 11 of 11

Thread: QT Creator doesn`t create main.moc.

  1. #1
    Join Date
    Sep 2010
    Posts
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default QT Creator doesn`t create main.moc.

    Hi. I`m totally beginner in QT. My problem is that I can`t compile examples like. Appchooser in Animation section. main.moc - no such file or directory. I didn`t change anything in a code. I qmake this manually but still nothing. Others examples, where class declaration is in .h file and definition in cpp works. I don`t have any idea why i can`t compile example

    EDIT: My system is WIN7, QT Creator 4.7.0, QT 4.6.3 and 4.7.

  2. #2
    Join Date
    May 2010
    Location
    Romania
    Posts
    1,021
    Thanks
    62
    Thanked 260 Times in 246 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: QT Creator doesn`t create main.moc.

    It does create it, but you should give the path to where qmake creates the file (now the generated files are not in the same folder with the files you create),
    Solution 1: replace this line:
    Qt Code:
    1. #include "main.moc"
    To copy to clipboard, switch view to plain text mode 
    with (you can check in the examples folder and see where the file is located):
    Qt Code:
    1. #include "tmp\moc\release_shared\main.moc"
    To copy to clipboard, switch view to plain text mode 

    And make sure that you link the 4.7 example with 4.7 library (if you have two versions you can select witch one to use)

    Or you can split the code from main.cpp and use an Pixmap.h and Pixmap.cpp for that class (and you won't have to include the .moc file)

  3. #3
    Join Date
    Sep 2010
    Posts
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QT Creator doesn`t create main.moc.

    Thank you very much. It works. Question is : Why QT creators didn`t include it like you?

    PS. Sorry for my poor english.

  4. #4
    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: QT Creator doesn`t create main.moc.

    You shouldn't need to do that. #include "main.moc" should work regardless of where the build directory is. There must be something else wrong there.
    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.


  5. #5
    Join Date
    May 2010
    Location
    Romania
    Posts
    1,021
    Thanks
    62
    Thanked 260 Times in 246 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: QT Creator doesn`t create main.moc.

    @Wysota: That example is "weird", it contains the definition and the implementation of a class in the main.cpp and, as far as i know, in this case the .moc file needs to be included in the .cpp file. Is there another way?

    Anyway: i didn't specified that the recommended solution is the second one: split the code from main.cpp and use an Pixmap.h, Pixmap.cpp and in main.cpp let only the the main function and necessary include (without the .moc include)

  6. #6
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: QT Creator doesn`t create main.moc.

    Quote Originally Posted by Zlatomir View Post
    @Wysota: That example is "weird", it contains the definition and the implementation of a class in the main.cpp and, as far as i know, in this case the .moc file needs to be included in the .cpp file. Is there another way?
    No, it must be there, but running qmake on such a file will normally set the correct path that make will find the moc file. Regardless where you compile it. Probably the make file was created before and then the path changed. Maybe a qmake rerun helps.

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

    Zlatomir (12th September 2010)

  8. #7
    Join Date
    May 2010
    Location
    Romania
    Posts
    1,021
    Thanks
    62
    Thanked 260 Times in 246 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: QT Creator doesn`t create main.moc.

    The qmake re-run doesn't help
    It "works" the same in on my main pc (Win 7), in linux (kubuntu) the same example runs fine with just #include "main.moc" (without path)

  9. #8
    Join Date
    May 2010
    Location
    Romania
    Posts
    1,021
    Thanks
    62
    Thanked 260 Times in 246 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: QT Creator doesn`t create main.moc.

    Quote Originally Posted by malootki View Post
    Thank you very much. It works. Question is : Why QT creators didn`t include it like you?
    Because it should work without specification of the path to that file, on linux it works, on windows it worked when the generated files where in the project folder, i guess that the mingw compiler search for that file only in project folder and can't find it because now the generated files (and .exe ...) are in a different folder. I didn't use this include very often, that is why i recommended you to split the example code in more files (a .h and a .cpp for that class) and in that case you don't need to include the .moc file

    PS:sorry for double post

  10. #9
    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: QT Creator doesn`t create main.moc.

    Quote Originally Posted by Zlatomir View Post
    i guess that the mingw compiler search for that file only in project folder and can't find it because now the generated files (and .exe ...) are in a different folder.
    That's what we have "-I" compiler directive and DEPENDPATH and INCLUDEPATH qmake variables. It should all work regardless of which platform you use unless you have a broken project file. Otherwise Qt itself wouldn't build.
    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.


  11. The following user says thank you to wysota for this useful post:

    Zlatomir (12th September 2010)

  12. #10
    Join Date
    May 2010
    Location
    Romania
    Posts
    1,021
    Thanks
    62
    Thanked 260 Times in 246 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: QT Creator doesn`t create main.moc.

    Wysota, thanks for the information, you are right it's only that "project" that doesn't work (i created a new one and it goes well)

    Looks like the example project builds if we delete the "Release" and "tmp" folders form the project folder "appchooser", the compiler will generate the new ones in the folder "appchooser-build-desktop"

    I still can't understand why in case of separate folders the old ones break the build, but when Qt Creator start to behave "strange" i think the deletion of old build files is what should be done first. Anyway i never had this problem with not finding a moc file because of the old build files.

  13. #11
    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: QT Creator doesn`t create main.moc.

    It's not Creator that causes the behaviour - it is just a text editor, nothing more. It's the compiler (drived by (n)make) that decides what to process and how.
    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.


Similar Threads

  1. Replies: 2
    Last Post: 20th April 2010, 21:27
  2. GLib-ERROR **: Cannot create pipe main loop wake-up
    By chenxuelian in forum Qt Programming
    Replies: 0
    Last Post: 2nd April 2010, 07:18
  3. Building Qt creator from gitorious main branch
    By eurodatar in forum Installation and Deployment
    Replies: 2
    Last Post: 8th September 2009, 14:20
  4. Resizeable main window in Qt Creator?
    By Lendrick in forum Qt Tools
    Replies: 2
    Last Post: 3rd June 2009, 19:57
  5. Qt Creator doesn't stop at breakpoints
    By TheSaw in forum Qt Tools
    Replies: 3
    Last Post: 12th May 2009, 15:53

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.