Results 1 to 5 of 5

Thread: Does not define type

  1. #1
    Join Date
    Jun 2011
    Posts
    203
    Thanks
    7
    Thanked 4 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Does not define type

    I have one class:

    field.h
    Qt Code:
    1. #ifndef FIELD_H
    2. #define FIELD_H
    3.  
    4. class Field : public QWidget
    5. etc
    6.  
    7. #endif
    To copy to clipboard, switch view to plain text mode 

    And then I have another class that uses this class as composition:

    Page.h
    Qt Code:
    1. #ifndef PAGE_H
    2. #define PAGE_H
    3.  
    4. #include "field.h"
    5.  
    6. class Page : public QWidget
    7. {
    8. Field array[10];
    9. }
    10.  
    11. #endif
    To copy to clipboard, switch view to plain text mode 

    At compile I get the error of 'Field' does not name a type, I don't know how to fix this? Internet seems to spring up a lot of circular includes as being the culprit however I don't understand how this is the case given that this is composition and I've got all my includes all up and running and it seems to work here:

    http://www.learncpp.com/cpp-tutorial/102-composition/

    !!!!!!!!!!!!!!!!!!!!!!!!! << sorry coding a line a week is frustrating. Every time something is added, a new error comes about and it's just beyond frustrating. Programing isn't my forte I don't think.

  2. #2
    Join Date
    Jun 2011
    Posts
    203
    Thanks
    7
    Thanked 4 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: Does not define type

    field.h
    Qt Code:
    1. #ifndef FIELD_H
    2. #define FIELD_H
    3.  
    4. #include <QWidget>
    5. #include <QMessageBox>
    6. #include <QDebug>
    7. #include <QString>
    8. #include <iostream>
    9. #include <string>
    10.  
    11. class Field : public QWidget
    12. {
    13. Q_OBJECT
    14. public:
    15. explicit Field(QWidget *parent = 0);
    16.  
    17. int m_iRow;
    18. int m_iColumn;
    19. std::string m_sText;
    20. int m_iColour;
    21.  
    22. void SetColour(int iColour);
    23. char FieldText();
    24. };
    25.  
    26. #endif
    To copy to clipboard, switch view to plain text mode 

    page.h
    Qt Code:
    1. #ifndef PAGE_H
    2. #define PAGE_H
    3.  
    4. #include <QWidget>
    5.  
    6. #include <iostream>
    7. #include <string>
    8.  
    9. #include "field.h"
    10. #include "selectablefield.h"
    11. #include "editablefield.h"
    12.  
    13. class Page : public QWidget
    14. {
    15. Q_OBJECT
    16. public:
    17. explicit Page(QWidget *parent = 0);
    18.  
    19. Page()
    20. {}
    21.  
    22. Field m_anField[220];
    23.  
    24. signals:
    25.  
    26. public slots:
    27.  
    28. };
    29.  
    30. #endif
    To copy to clipboard, switch view to plain text mode 

    Error that I get is:

    \page.h:39: error: 'Field' does not name a type

    compile output is:

    In file included from ../mainwindow.h:6,
    /field.h:13,
    from \field.cpp:1:
    /page.h:39: error: 'Field' does not name a type
    mingw32-make[1]: Leaving directory `D:/Users/...
    mingw32-make[1]: *** [debug/field.o] Error 1
    mingw32-make: *** [debug] Error 2
    The process "D:\QtSDK\mingw\bin\mingw32-make.exe" exited with code 2.
    Error while building project ... (target: Desktop)
    When executing build step 'Make'

  3. #3
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Does not define type

    What does the top of field.cpp look like? Is it really in the root directory of you drive as this would imply?
    Qt Code:
    1. In file included from ../mainwindow.h:6,
    2. /field.h:13,
    3. from \field.cpp:1: <<<<< here
    To copy to clipboard, switch view to plain text mode 

    Is everything in the same directory?
    Is there more than one file called "field.h" in your project?
    "We can't solve problems by using the same kind of thinking we used when we created them." -- Einstein
    If you are posting code then please use [code] [/code] tags around it - makes addressing the problem easier.

  4. #4
    Join Date
    Jun 2011
    Posts
    203
    Thanks
    7
    Thanked 4 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: Does not define type

    Found the error, you were pretty close from what I can gather. I had an #include field.h in my main.cpp file and for some reason that was what was causing the issue. I'm not sure why this was the case given that I was using header guards.

  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: Does not define type

    Your code is invalid -- widgets cannot be copied thus you shouldn't have an array of Field objects. Instead you can have an array of Field pointers.
    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. how to define a new line type
    By xiongxiongchuan in forum Qt Programming
    Replies: 2
    Last Post: 3rd May 2011, 07:20
  2. Unable to define a new type with QVariant
    By max2g in forum Qt Programming
    Replies: 3
    Last Post: 23rd February 2008, 17:55
  3. tr with #define..it can work?
    By mattia in forum Newbie
    Replies: 9
    Last Post: 4th February 2008, 11:15
  4. #define MYCLASS_H ?
    By bnilsson in forum General Programming
    Replies: 1
    Last Post: 3rd February 2008, 10:50
  5. where should i put #define in QtDesigner?
    By nass in forum Qt Tools
    Replies: 1
    Last Post: 16th October 2006, 15:52

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.