Results 1 to 6 of 6

Thread: Qt forbid declaration of QListView with no type

  1. #1
    Join Date
    May 2011
    Posts
    7
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows Maemo/MeeGo

    Default Qt forbid declaration of QListView with no type

    I have a very strange error in my Qt project. Here is the code, the main_window.h:


    Qt Code:
    1. #include <QtGui>
    2. #include <QtSql>
    3.  
    4. class main_window : public QTabWidget
    5. {
    6. Q_OBJECT
    7.  
    8. /// @name List Widgets
    9. private:
    10. QListWidget* m_documents_list;
    11. ....
    To copy to clipboard, switch view to plain text mode 


    and here is main_window.cpp:

    Qt Code:
    1. ...
    2. void main_window::create_documents_widget()
    3. {
    4. m_documents = new QWidget(this);
    5. m_documents_list = new QListWidget(m_documents);
    6. }
    7. ...
    To copy to clipboard, switch view to plain text mode 

    The problem that I can't understand is in QListView, I'm not using it in my project. There is only QListWidget, but when I'm trying to build the project the following errors occur:

    qlistview.h:194: error: ISO C++ forbids declaration of 'QListView' with no type

    qlistview.h:194: error: expected ',' or '...' before '&' token

    Also the following strange errors:

    qlistwidget.h:308: error: no 'void QListWidget::removeItemWidget(QListWidgetItem*)' member function declared in class 'QListWidget'

    qlistwidget.h:311: error: no 'void QListWidget::addItem(QListWidgetItem*)' member function declared in class 'QListWidget'

    qlistwidget.h:314: error: no 'QListWidgetItem* QListWidget::itemAt(int, int) const' member function declared in class 'QListWidget'

    etc.

    Thanks in advance.

    UPD: I'm using QtCreator 2.2.1 on Windows 7.

    UPD2: Qt version is 4.7.1.

    UPD3: The complete output

    Qt Code:
    1. In file included from c:\QtSDK\Desktop\Qt\4.7.3\mingw\include\QtGui/QtGui:68,
    2. from ..\my_project\/main_window.h:4,
    3. from ..\my_project\main.cpp:2:
    4. c:\QtSDK\Desktop\Qt\4.7.3\mingw\include\QtGui/qlistview.h:194: error: ISO C++ forbids declaration of 'QListView' with no type
    5. c:\QtSDK\Desktop\Qt\4.7.3\mingw\include\QtGui/qlistview.h:194: error: expected ',' or '...' before '&' token
    6. c:\QtSDK\Desktop\Qt\4.7.3\mingw\include\QtGui/qlistview.h:194: error: ISO C++ forbids declaration of 'QListView' with no type
    7. c:\QtSDK\Desktop\Qt\4.7.3\mingw\include\QtGui/qlistview.h:194: error: ISO C++ forbids declaration of 'QListView' with no type
    8. c:\QtSDK\Desktop\Qt\4.7.3\mingw\include\QtGui/qlistview.h:194: error: expected ';' before '&' token
    9. In file included from c:\QtSDK\Desktop\Qt\4.7.3\mingw\include\QtGui/QtGui:69,
    10. from ..\my_project\/main_window.h:4,
    11. from ..\my_project\main.cpp:2:
    12. c:\QtSDK\Desktop\Qt\4.7.3\mingw\include\QtGui/qlistwidget.h:202: error: redefinition of 'class QListWidget'
    13. c:\QtSDK\Desktop\Qt\4.7.3\mingw\include\QtGui/qlistview.h:58: error: previous definition of 'class QListWidget'
    14. c:\QtSDK\Desktop\Qt\4.7.3\mingw\include\QtGui/qlistwidget.h:308: error: no 'void QListWidget::removeItemWidget(QListWidgetItem*)' member function declared in class 'QListWidget'
    15. c:\QtSDK\Desktop\Qt\4.7.3\mingw\include\QtGui/qlistwidget.h:311: error: no 'void QListWidget::addItem(QListWidgetItem*)' member function declared in class 'QListWidget'
    16. c:\QtSDK\Desktop\Qt\4.7.3\mingw\include\QtGui/qlistwidget.h:314: error: no 'QListWidgetItem* QListWidget::itemAt(int, int) const' member function declared in class 'QListWidget'
    17. c:\QtSDK\Desktop\Qt\4.7.3\mingw\include\QtGui/qlistwidget.h: In member function 'void QListWidgetItem::setSelected(bool)':
    18. c:\QtSDK\Desktop\Qt\4.7.3\mingw\include\QtGui/qlistwidget.h:318: error: 'class QListWidget' has no member named 'setItemSelected'
    19. c:\QtSDK\Desktop\Qt\4.7.3\mingw\include\QtGui/qlistwidget.h: In member function 'bool QListWidgetItem::isSelected() const':
    20. c:\QtSDK\Desktop\Qt\4.7.3\mingw\include\QtGui/qlistwidget.h:321: error: 'class QListWidget' has no member named 'isItemSelected'
    21. c:\QtSDK\Desktop\Qt\4.7.3\mingw\include\QtGui/qlistwidget.h: In member function 'void QListWidgetItem::setHidden(bool)':
    22. c:\QtSDK\Desktop\Qt\4.7.3\mingw\include\QtGui/qlistwidget.h:324: error: 'class QListWidget' has no member named 'setItemHidden'
    23. c:\QtSDK\Desktop\Qt\4.7.3\mingw\include\QtGui/qlistwidget.h: In member function 'bool QListWidgetItem::isHidden() const':
    24. c:\QtSDK\Desktop\Qt\4.7.3\mingw\include\QtGui/qlistwidget.h:327: error: 'class QListWidget' has no member named 'isItemHidden'
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Apr 2011
    Location
    Russia
    Posts
    85
    Thanks
    2
    Thanked 13 Times in 13 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qt forbid declaration of QListView with no type

    Do you include QListWidget? #include <QListWidget>

  3. #3
    Join Date
    May 2011
    Posts
    7
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows Maemo/MeeGo

    Default Re: Qt forbid declaration of QListView with no type

    Yes, I've included.

  4. #4
    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 forbid declaration of QListView with no type

    Hm, it seems you have declared your own class named QListWidget. Or you used
    Qt Code:
    To copy to clipboard, switch view to plain text mode 
    somewhere. Can we see more code, or make a minimal, »compilable« example, reproducing your problem.

  5. #5
    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: Qt forbid declaration of QListView with no type

    The problem that I can't understand is in QListView, I'm not using it in my project. There is only QListWidget,
    QListWidget inherits QListView.

    UPD2: Qt version is 4.7.1.
    The error messages are clearly coming from a Qt 4.7.3 install. I would start by rerunning qmake to make sure the right qmake is used and Makefile is constructed.

    If the problem persists look at the lines of your code leading up to the line 4 of main_window.h (the one that starts the error) looking for missing semicolons and the like. There can only be a few lines (the ones you have given us don't quite match the error messages).

  6. #6
    Join Date
    May 2011
    Posts
    7
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows Maemo/MeeGo

    Default Re: Qt forbid declaration of QListView with no type

    It seems my project is kidding on me. The build gives various "unknown"(to me) errors. I'm getting angry, is it possible that QtCreator sucks and Qt Windows SDK sucks, too?
    Here is all my code:

    main_window.h

    Qt Code:
    1. #ifndef MAIN_WINDOW_H
    2. #define MAIN_WINDOW_H
    3.  
    4. #include <QTabWidget>
    5. #include <QVBoxLayout>
    6. #include <QtSql>
    7. #include <QListWidget>
    8.  
    9. class main_window : public QTabWidget
    10. {
    11. Q_OBJECT
    12.  
    13. /// @name Special methods
    14. public:
    15. main_window(QWidget* parent = 0);
    16. virtual ~main_window();
    17.  
    18. /// @name Helpers
    19. private:
    20. void complete_main_window();
    21.  
    22. private:
    23. void create_tabs();
    24.  
    25. private:
    26. void create_widgets();
    27. void create_documents_widgets();
    28. void create_keywords_widgets();
    29. void create_references_widgets();
    30.  
    31. private:
    32. QWidget* m_documents;
    33. QWidget* m_keywords;
    34. QWidget* m_references;
    35.  
    36. private:
    37. void setup_layout();
    38. void setup_documents_layout();
    39. void setup_keywords_layout();
    40. void setup_references_layout();
    41.  
    42. private:
    43. QVBoxLayout* m_documents_layout;
    44. QVBoxLayout* m_keywords_layout;
    45. QVBoxLayout* m_references_layout;
    46.  
    47. private:
    48. void make_connections();
    49.  
    50. private:
    51. void initialize_database();
    52. void fill_contents();
    53. void fill_documents_content();
    54. void fill_keywords_content();
    55. void fill_references_content();
    56.  
    57. private:
    58. QSqlDatabase m_database;
    59. QSqlQuery* m_query;
    60. };
    61.  
    62. #endif // MAIN_WINDOW_H
    To copy to clipboard, switch view to plain text mode 

    main_window.cpp

    Qt Code:
    1. #include "main_window.h"
    2.  
    3. main_window::main_window(QWidget* parent)
    4. : QTabWidget(parent)
    5. {
    6. create_widgets();
    7. setup_layout();
    8. create_tabs();
    9. complete_main_window();
    10. }
    11.  
    12. main_window::~main_window()
    13. {
    14. }
    15.  
    16. void main_window::complete_main_window()
    17. {
    18. showMaximized();
    19. show();
    20. }
    21.  
    22. void main_window::create_tabs()
    23. {
    24. addTab(m_documents, "Documents");
    25. addTab(m_keywords, "Keywords");
    26. addTab(m_references, "References");
    27. }
    28.  
    29. void main_window::create_widgets()
    30. {
    31. create_documents_widgets();
    32. create_keywords_widgets();
    33. create_references_widgets();
    34. }
    35.  
    36. void main_window::create_documents_widgets()
    37. {
    38. m_documents = new QWidget(this);
    39. }
    40.  
    41. void main_window::create_keywords_widgets()
    42. {
    43. m_keywords = new QWidget(this);
    44. }
    45.  
    46. void main_window::create_references_widgets()
    47. {
    48. m_references = new QWidget(this);
    49. }
    50.  
    51. void main_window::setup_layout()
    52. {
    53. setup_documents_layout();
    54. setup_keywords_layout();
    55. setup_references_layout();
    56. }
    57.  
    58. void main_window::setup_documents_layout()
    59. {
    60. m_documents_layout = new QVBoxLayout(this);
    61. m_documents->setLayout(m_documents_layout);
    62. }
    63.  
    64. void main_window::setup_keywords_layout()
    65. {
    66. m_keywords_layout = new QVBoxLayout(this);
    67. m_keywords->setLayout(m_keywords_layout);
    68. }
    69.  
    70. void main_window::setup_references_layout()
    71. {
    72. m_references_layout = new QVBoxLayout(this);
    73. m_references->setLayout(m_references_layout);
    74. }
    75.  
    76. void main_window::make_connections()
    77. {
    78.  
    79. }
    80.  
    81. void main_window::initialize_database()
    82. {
    83. m_database = QSqlDatabase::addDatabase("QSQLITE");
    84. m_database.setDatabaseName("main_database.sqlite");
    85. if (!m_database.open()) {
    86. qDebug() << "Can't open DB";
    87. }
    88. m_query = new QSqlQuery(m_database);
    89. }
    90.  
    91. void main_window::fill_contents()
    92. {
    93. fill_documents_content();
    94. fill_keywords_content();
    95. fill_references_content();
    96. }
    97.  
    98. void main_window::fill_documents_content()
    99. {
    100. // logic here
    101. }
    102.  
    103. void main_window::fill_keywords_content()
    104. {
    105. //logic here
    106. }
    107.  
    108. void main_window::fill_references_content()
    109. {
    110. //logic here
    111. }
    To copy to clipboard, switch view to plain text mode 

    And, finally, main.cpp

    Qt Code:
    1. #include <QApplication>
    2.  
    3. #include "main_window.h"
    4.  
    5. int main(int argc, char** argv)
    6. {
    7. QApplication app(argc, argv);
    8. main_window w;
    9. w.show();
    10.  
    11. return app.exec();
    12. }
    To copy to clipboard, switch view to plain text mode 

    I got the following output (for now, I'm sure if I change something, even add a comment, the errors will increase ):

    Qt Code:
    1. unning build steps for project my_project...
    2. Configuration unchanged, skipping qmake step.
    3. Starting: "C:\QtSDK\mingw\bin\mingw32-make.exe"
    4. C:/QtSDK/mingw/bin/mingw32-make -f Makefile.Debug
    5. mingw32-make[1]: Entering directory `C:/Users/vardg/Documents/qt_projects/my_project-build-desktop'
    6. g++ -c -g -frtti -fexceptions -mthreads -Wall -DUNICODE -DQT_LARGEFILE_SUPPORT -DQT_DLL -DQT_SQL_LIB -DQT_GUI_LIB -DQT_CORE_LIB -DQT_HAVE_MMX -DQT_HAVE_3DNOW -DQT_HAVE_SSE -DQT_HAVE_MMXEXT -DQT_HAVE_SSE2 -DQT_THREAD_SUPPORT -DQT_NEEDS_QMAIN -I"c:\QtSDK\Desktop\Qt\4.7.3\mingw\include\QtCore" -I"c:\QtSDK\Desktop\Qt\4.7.3\mingw\include\QtGui" -I"c:\QtSDK\Desktop\Qt\4.7.3\mingw\include\QtSql" -I"c:\QtSDK\Desktop\Qt\4.7.3\mingw\include" -I"c:\QtSDK\Desktop\Qt\4.7.3\mingw\include\ActiveQt" -I"debug" -I"..\my_project" -I"." -I"c:\QtSDK\Desktop\Qt\4.7.3\mingw\mkspecs\win32-g++" -o debug\main.o ..\my_project\main.cpp
    7. In file included from c:\QtSDK\Desktop\Qt\4.7.3\mingw\include\QtSql/qsqlrelationaldelegate.h:48,
    8. from c:\QtSDK\Desktop\Qt\4.7.3\mingw\include\QtSql/QtSql:15,
    9. from ..\my_project\/main_window.h:6,
    10. from ..\my_project\main.cpp:4:
    11. c:\QtSDK\Desktop\Qt\4.7.3\mingw\include/QtGui/qlistview.h:57: error: redefinition of 'class QWidget'
    12. c:\QtSDK\Desktop\Qt\4.7.3\mingw\include/QtGui/qwidget.h:141: error: previous definition of 'class QWidget'
    13. In file included from c:\QtSDK\Desktop\Qt\4.7.3\mingw\include\QtGui/QListWidget:1,
    14. from ..\my_project\/main_window.h:7,
    15. from ..\my_project\main.cpp:4:
    16. c:\QtSDK\Desktop\Qt\4.7.3\mingw\include\QtGui/qlistwidget.h:202: error: redefinition of 'class QWidget'
    17. c:\QtSDK\Desktop\Qt\4.7.3\mingw\include/QtGui/qwidget.h:141: error: previous definition of 'class QWidget'
    18. c:\QtSDK\Desktop\Qt\4.7.3\mingw\include\QtGui/qlistwidget.h:308: error: no 'void QWidget::removeItemWidget(QListWidgetItem*)' member function declared in class 'QWidget'
    19. c:\QtSDK\Desktop\Qt\4.7.3\mingw\include\QtGui/qlistwidget.h:311: error: no 'void QWidget::addItem(QListWidgetItem*)' member function declared in class 'QWidget'
    20. c:\QtSDK\Desktop\Qt\4.7.3\mingw\include\QtGui/qlistwidget.h:314: error: no 'QListWidgetItem* QWidget::itemAt(int, int) const' member function declared in class 'QWidget'
    21. c:\QtSDK\Desktop\Qt\4.7.3\mingw\include\QtGui/qlistwidget.h: In member function 'void QListWidgetItem::setSelected(bool)':
    22. c:\QtSDK\Desktop\Qt\4.7.3\mingw\include\QtGui/qlistwidget.h:318: error: 'class QWidget' has no member named 'setItemSelected'
    23. c:\QtSDK\Desktop\Qt\4.7.3\mingw\include\QtGui/qlistwidget.h: In member function 'bool QListWidgetItem::isSelected() const':
    24. c:\QtSDK\Desktop\Qt\4.7.3\mingw\include\QtGui/qlistwidget.h:321: error: 'class QWidget' has no member named 'isItemSelected'
    25. c:\QtSDK\Desktop\Qt\4.7.3\mingw\include\QtGui/qlistwidget.h: In member function 'void QListWidgetItem::setHidden(bool)':
    26. c:\QtSDK\Desktop\Qt\4.7.3\mingw\include\QtGui/qlistwidget.h:324: error: 'class QWidget' has no member named 'setItemHidden'
    27. c:\QtSDK\Desktop\Qt\4.7.3\mingw\include\QtGui/qlistwidget.h: In member function 'bool QListWidgetItem::isHidden() const':
    28. c:\QtSDK\Desktop\Qt\4.7.3\mingw\include\QtGui/qlistwidget.h:327: error: 'class QWidget' has no member named 'isItemHidden'
    29. mingw32-make[1]: Leaving directory `C:/Users/vardg/Documents/qt_projects/my_project-build-desktop'
    30. mingw32-make[1]: *** [debug/main.o] Error 1
    31. mingw32-make: *** [debug] Error 2
    32. The process "C:\QtSDK\mingw\bin\mingw32-make.exe" exited with code 2.
    33. Error while building project my_project(target: Desktop)
    34. When executing build step 'Make'
    To copy to clipboard, switch view to plain text mode 

    Here is, just in case, the .pro file

    Qt Code:
    1. QT += core gui sql
    2.  
    3. TARGET = my_project
    4. TEMPLATE = app
    5.  
    6.  
    7. SOURCES += main.cpp\
    8. main_window.cpp
    9.  
    10. HEADERS += main_window.h
    To copy to clipboard, switch view to plain text mode 

    Extra great thanks in advance, also thanks for previous replies, waiting for solution....

Similar Threads

  1. error ISO C++ forbids declaration of 'obj' with no type
    By naturalpsychic in forum Qt Programming
    Replies: 1
    Last Post: 26th January 2011, 06:23
  2. Replies: 2
    Last Post: 10th October 2010, 16:38
  3. Replies: 13
    Last Post: 31st July 2010, 15:19
  4. Replies: 12
    Last Post: 29th April 2010, 13:22
  5. forbids declaration of QHash with no type
    By nina1983 in forum Qt Programming
    Replies: 4
    Last Post: 16th July 2008, 13:05

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.