+ Reply to Thread
Results 1 to 4 of 4

Thread: PCH and QtCreator warning of not finding the type name

  1. #1
    Join Date
    Sep 2010
    Location
    Poland
    Posts
    112
    Thanks
    8
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Maemo/MeeGo

    Default PCH and QtCreator warning of not finding the type name

    recently I found that I can make my compilation faster using PCH file, so decided to go on it, prepared suitable _pch.h header file when I put all includes I use in my whole project and I keep repeating the same includes in many header files (I assume this is one of the additional-feature of pch.h, make me correct, if I'm wrong). I also modified my *.pro file (basing on docs), below is the snippet from it
    Qt Code:
    1. CONFIG += precompile_header
    2. PRECOMPILED_HEADER = _pch.h ####it is a precompiled headear file
    3. precompile_header:!isEmpty(PRECOMPILED_HEADER) {
    4. DEFINES += USING_PCH
    5. }
    To copy to clipboard, switch view to plain text mode 

    and here is _pch.h
    Qt Code:
    1. #ifndef _PCH_H
    2. #define _PCH_H
    3. #if defined __cplusplus
    4. #include <QtCore>
    5. #include <QtGui>
    6. #include <QDebug>
    7. #include <QList>
    8. #include <QPointer>
    9. #include <QObject>
    10. #include <QString>
    11. #endif
    12. #endif // _PCH_H
    To copy to clipboard, switch view to plain text mode 

    and from now on it works pretty well, nevertheless in some headers (not all) I have a warning from QtCreator that for example QString or QPointer is not a type name, where in other headers this warning is not produced

    it is both very interesting that in some files there is no warning and very annoying because underlined lines of code are like red rag though it does not affect on compilation process

    perhaps I did something wrong or assumed something which in obvious way is a mistake and my code is a time bomb from now on ?
    My schedule makes my cry
    My works makes my laugh
    My life makes... oh...no....

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    31,203
    Thanks
    3
    Thanked 4,694 Times in 4,495 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Blog Entries
    4
    Wiki edits
    10

    Default Re: PCH and QtCreator warning of not finding the type name

    If you have a pch file then you don't need to put the actual include statements in source files and still the compilation succeeds. But since Creator doesn't use the pch file in any way, it needs those include statements to be there to properly parse your code.
    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.


  3. #3
    Join Date
    Sep 2010
    Location
    Poland
    Posts
    112
    Thanks
    8
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Maemo/MeeGo

    Default Re: PCH and QtCreator warning of not finding the type name

    so I see solution with pch is rather tricky, as compiler knows everything is OK in opposite to Creator.

    but let me ask this question, because this part is not so obvious to me and I've not encountered this ever before. If I add includes to headers separately from what's in pch, won't it be like overriding and including something twice, which is obviously unnecessary?
    My schedule makes my cry
    My works makes my laugh
    My life makes... oh...no....

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    31,203
    Thanks
    3
    Thanked 4,694 Times in 4,495 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Blog Entries
    4
    Wiki edits
    10

    Default Re: PCH and QtCreator warning of not finding the type name

    Quote Originally Posted by kornicameister View Post
    so I see solution with pch is rather tricky, as compiler knows everything is OK in opposite to Creator.
    It's not tricky if you remember that having a precompiled header doesn't allow you to not include individual files in your code. It works because of the way precompiled headers work but syntactically this is incorrect. You are just abusing a side effect of PCH.

    If I add includes to headers separately from what's in pch, won't it be like overriding and including something twice, which is obviously unnecessary?
    The compiler will either know a particular file is part of the pch and will not parse it again (which I doubt is the case) or it will encounter a #ifndef GUARD_H, #define GUARD_H, #endif clause that will prevent the file from being parsed again. Actually I think there is probably some hybrid solution to this but this might be compiler dependent.
    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.


+ Reply to Thread

Similar Threads

  1. Replies: 7
    Last Post: 19th April 2011, 12:20
  2. QtCreator 2.0 crashes application working in QtCreator 1.3
    By been_1990 in forum Qt Programming
    Replies: 2
    Last Post: 21st September 2010, 12:58
  3. QtCreator warning underlines in text editor
    By chaoticbob in forum Qt Tools
    Replies: 6
    Last Post: 29th December 2009, 23:46
  4. Replies: 2
    Last Post: 22nd December 2009, 20:52
  5. Type and User Type
    By campana in forum Qt Programming
    Replies: 1
    Last Post: 27th February 2006, 23:22

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