Question

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

#include <QtGui>
#include <QtSql>

class main_window : public QTabWidget
{
    Q_OBJECT

    /// @name List Widgets
private:
    QListWidget*    m_documents_list;
....

and here is main_window.cpp:

...
void main_window::create_documents_widget()
{
    m_documents = new QWidget(this);
    m_documents_list = new QListWidget(m_documents);
}
...

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

In file included from c:\QtSDK\Desktop\Qt\4.7.3\mingw\include\QtGui/QtGui:68,
                 from ..\my_project\/main_window.h:4,
                 from ..\my_project\main.cpp:2:
c:\QtSDK\Desktop\Qt\4.7.3\mingw\include\QtGui/qlistview.h:194: error: ISO C++ forbids declaration of 'QListView' with no type
c:\QtSDK\Desktop\Qt\4.7.3\mingw\include\QtGui/qlistview.h:194: error: expected ',' or '...' before '&' token
c:\QtSDK\Desktop\Qt\4.7.3\mingw\include\QtGui/qlistview.h:194: error: ISO C++ forbids declaration of 'QListView' with no type
c:\QtSDK\Desktop\Qt\4.7.3\mingw\include\QtGui/qlistview.h:194: error: ISO C++ forbids declaration of 'QListView' with no type
c:\QtSDK\Desktop\Qt\4.7.3\mingw\include\QtGui/qlistview.h:194: error: expected ';' before '&' token
In file included from c:\QtSDK\Desktop\Qt\4.7.3\mingw\include\QtGui/QtGui:69,
                 from ..\my_project\/main_window.h:4,
                 from ..\my_project\main.cpp:2:
c:\QtSDK\Desktop\Qt\4.7.3\mingw\include\QtGui/qlistwidget.h:202: error: redefinition of 'class QListWidget'
c:\QtSDK\Desktop\Qt\4.7.3\mingw\include\QtGui/qlistview.h:58: error: previous definition of 'class QListWidget'
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'
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'
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'
c:\QtSDK\Desktop\Qt\4.7.3\mingw\include\QtGui/qlistwidget.h: In member function 'void QListWidgetItem::setSelected(bool)':
c:\QtSDK\Desktop\Qt\4.7.3\mingw\include\QtGui/qlistwidget.h:318: error: 'class QListWidget' has no member named 'setItemSelected'
c:\QtSDK\Desktop\Qt\4.7.3\mingw\include\QtGui/qlistwidget.h: In member function 'bool QListWidgetItem::isSelected() const':
c:\QtSDK\Desktop\Qt\4.7.3\mingw\include\QtGui/qlistwidget.h:321: error: 'class QListWidget' has no member named 'isItemSelected'
c:\QtSDK\Desktop\Qt\4.7.3\mingw\include\QtGui/qlistwidget.h: In member function 'void QListWidgetItem::setHidden(bool)':
c:\QtSDK\Desktop\Qt\4.7.3\mingw\include\QtGui/qlistwidget.h:324: error: 'class QListWidget' has no member named 'setItemHidden'
c:\QtSDK\Desktop\Qt\4.7.3\mingw\include\QtGui/qlistwidget.h: In member function 'bool QListWidgetItem::isHidden() const':
c:\QtSDK\Desktop\Qt\4.7.3\mingw\include\QtGui/qlistwidget.h:327: error: 'class QListWidget' has no member named 'isItemHidden'
Was it helpful?

Solution

Firstly - you should also mention qt version, as in this case that's most important.

This seems like some weird quirk of compiler or qt - my recomendation would be first to create simplest program where problem occurs. If it shows also in program like

#include <QtGui/QListWidget>
int main(int argc, char* argv[]){
    QListWidget* w = 0;
}

then it is some problem with qt headers of compiler - then answer cannot be provided from data provided. If it works, then try to slowly add other elements of your code to this simple file - most likely at some point you will get the same error again - then you will know that last added piece of code is guilty. Some additional thinking might be required to figure out how to remove problem once located.

OTHER TIPS

It should be noted that QListWidget inherits from QListView, so you are indirectly using it.

The error your getting looks like you're simply missing a #include <QListWidget> line in your header file.

Also, it could be that that you're missing #include guards in your header file

#ifndef MYCLASS
#define MYCLASS

class MyClass { ... };

#endif

If your header file is #included by more than one project then that would explain the errors you're seeing.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top