Results 1 to 5 of 5

Thread: forbids declaration of QHash with no type

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jul 2008
    Posts
    26
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: forbids declaration of QHash with no type

    ok....

    I solve the problem including:

    Qt Code:
    1. #include<QHash>
    2. #include<QStringList>
    To copy to clipboard, switch view to plain text mode 


    but I have one more question...
    Before I added "hash" and "hashName", I had only QString and QList object in my header file. Why I don't have to include this classes? It worked withouth the declaration
    Qt Code:
    1. #include <QString>
    2. #include <QList>
    To copy to clipboard, switch view to plain text mode 
    Why QHash and QStringList need it?

    Thanks
    Last edited by jpn; 21st July 2008 at 17:26. Reason: missing [code] tags

  2. #2
    Join Date
    Dec 2006
    Posts
    849
    Thanks
    6
    Thanked 163 Times in 151 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: forbids declaration of QHash with no type

    If you use a (any) Qt-class, in a header you usually need to include its header.

    Exceptions are:
    * if you only use a pointer or reference or return type, a forward declaration is enough.

    Qt Code:
    1. class X
    2. {
    3. QString s; // needs include
    4. QTreeView *tv; // forward decl "class QTreeView;" is enough
    5. QHash<QString,QList<int> > hash; // needs includes for QString, QList and QHash
    6. QString getName() const; // forward declaration enough
    7. };
    To copy to clipboard, switch view to plain text mode 

    Sometimes you get away without including a header, namely if you include other headers that in turn include the header you would need.
    Still, I consider it good practice to explicitly include any header of a class that is explicitly used in a class.

    In your case: QStringList inherits QList. Therefore its header must include the QList-header. Thus you do not have to include it.
    QString is part of QStringList as well.

    HTH

  3. #3
    Join Date
    Jul 2008
    Posts
    26
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: forbids declaration of QHash with no type

    Great!

    Now I understand!

    Thank you so much!


Similar Threads

  1. Installation on Fedora Core 4
    By jcr in forum Installation and Deployment
    Replies: 3
    Last Post: 29th January 2009, 01:34
  2. Compile 4.4.0
    By LordQt in forum Installation and Deployment
    Replies: 18
    Last Post: 29th May 2008, 13:43
  3. problem with forward declaration
    By MarkoSan in forum General Programming
    Replies: 14
    Last Post: 6th January 2008, 21:45
  4. dummy question(Error)
    By Masih in forum Qt Programming
    Replies: 12
    Last Post: 19th July 2007, 23:38
  5. Compile Errors
    By luffy27 in forum Qt Programming
    Replies: 3
    Last Post: 4th November 2006, 05:26

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.