PDA

View Full Version : Qt forbid declaration of QListView with no type



Dehumanizer
19th September 2011, 08:28
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'

Jonny174
19th September 2011, 09:36
Do you include QListWidget? #include <QListWidget>

Dehumanizer
19th September 2011, 09:54
Yes, I've included.

Lykurg
19th September 2011, 10:11
Hm, it seems you have declared your own class named QListWidget. Or you used
QListWidget; somewhere. Can we see more code, or make a minimal, »compilable« example, reproducing your problem.

ChrisW67
19th September 2011, 10:13
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).

Dehumanizer
19th September 2011, 11:21
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


#ifndef MAIN_WINDOW_H
#define MAIN_WINDOW_H

#include <QTabWidget>
#include <QVBoxLayout>
#include <QtSql>
#include <QListWidget>

class main_window : public QTabWidget
{
Q_OBJECT

/// @name Special methods
public:
main_window(QWidget* parent = 0);
virtual ~main_window();

/// @name Helpers
private:
void complete_main_window();

private:
void create_tabs();

private:
void create_widgets();
void create_documents_widgets();
void create_keywords_widgets();
void create_references_widgets();

private:
QWidget* m_documents;
QWidget* m_keywords;
QWidget* m_references;

private:
void setup_layout();
void setup_documents_layout();
void setup_keywords_layout();
void setup_references_layout();

private:
QVBoxLayout* m_documents_layout;
QVBoxLayout* m_keywords_layout;
QVBoxLayout* m_references_layout;

private:
void make_connections();

private:
void initialize_database();
void fill_contents();
void fill_documents_content();
void fill_keywords_content();
void fill_references_content();

private:
QSqlDatabase m_database;
QSqlQuery* m_query;
};

#endif // MAIN_WINDOW_H


main_window.cpp



#include "main_window.h"

main_window::main_window(QWidget* parent)
: QTabWidget(parent)
{
create_widgets();
setup_layout();
create_tabs();
complete_main_window();
}

main_window::~main_window()
{
}

void main_window::complete_main_window()
{
showMaximized();
show();
}

void main_window::create_tabs()
{
addTab(m_documents, "Documents");
addTab(m_keywords, "Keywords");
addTab(m_references, "References");
}

void main_window::create_widgets()
{
create_documents_widgets();
create_keywords_widgets();
create_references_widgets();
}

void main_window::create_documents_widgets()
{
m_documents = new QWidget(this);
}

void main_window::create_keywords_widgets()
{
m_keywords = new QWidget(this);
}

void main_window::create_references_widgets()
{
m_references = new QWidget(this);
}

void main_window::setup_layout()
{
setup_documents_layout();
setup_keywords_layout();
setup_references_layout();
}

void main_window::setup_documents_layout()
{
m_documents_layout = new QVBoxLayout(this);
m_documents->setLayout(m_documents_layout);
}

void main_window::setup_keywords_layout()
{
m_keywords_layout = new QVBoxLayout(this);
m_keywords->setLayout(m_keywords_layout);
}

void main_window::setup_references_layout()
{
m_references_layout = new QVBoxLayout(this);
m_references->setLayout(m_references_layout);
}

void main_window::make_connections()
{

}

void main_window::initialize_database()
{
m_database = QSqlDatabase::addDatabase("QSQLITE");
m_database.setDatabaseName("main_database.sqlite");
if (!m_database.open()) {
qDebug() << "Can't open DB";
}
m_query = new QSqlQuery(m_database);
}

void main_window::fill_contents()
{
fill_documents_content();
fill_keywords_content();
fill_references_content();
}

void main_window::fill_documents_content()
{
// logic here
}

void main_window::fill_keywords_content()
{
//logic here
}

void main_window::fill_references_content()
{
//logic here
}


And, finally, main.cpp



#include <QApplication>

#include "main_window.h"

int main(int argc, char** argv)
{
QApplication app(argc, argv);
main_window w;
w.show();

return app.exec();
}


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


unning build steps for project my_project...
Configuration unchanged, skipping qmake step.
Starting: "C:\QtSDK\mingw\bin\mingw32-make.exe"
C:/QtSDK/mingw/bin/mingw32-make -f Makefile.Debug
mingw32-make[1]: Entering directory `C:/Users/vardg/Documents/qt_projects/my_project-build-desktop'
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
In file included from c:\QtSDK\Desktop\Qt\4.7.3\mingw\include\QtSql/qsqlrelationaldelegate.h:48,
from c:\QtSDK\Desktop\Qt\4.7.3\mingw\include\QtSql/QtSql:15,
from ..\my_project\/main_window.h:6,
from ..\my_project\main.cpp:4:
c:\QtSDK\Desktop\Qt\4.7.3\mingw\include/QtGui/qlistview.h:57: error: redefinition of 'class QWidget'
c:\QtSDK\Desktop\Qt\4.7.3\mingw\include/QtGui/qwidget.h:141: error: previous definition of 'class QWidget'
In file included from c:\QtSDK\Desktop\Qt\4.7.3\mingw\include\QtGui/QListWidget:1,
from ..\my_project\/main_window.h:7,
from ..\my_project\main.cpp:4:
c:\QtSDK\Desktop\Qt\4.7.3\mingw\include\QtGui/qlistwidget.h:202: error: redefinition of 'class QWidget'
c:\QtSDK\Desktop\Qt\4.7.3\mingw\include/QtGui/qwidget.h:141: error: previous definition of 'class QWidget'
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'
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'
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'
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 QWidget' 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 QWidget' 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 QWidget' 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 QWidget' has no member named 'isItemHidden'
mingw32-make[1]: Leaving directory `C:/Users/vardg/Documents/qt_projects/my_project-build-desktop'
mingw32-make[1]: *** [debug/main.o] Error 1
mingw32-make: *** [debug] Error 2
The process "C:\QtSDK\mingw\bin\mingw32-make.exe" exited with code 2.
Error while building project my_project(target: Desktop)
When executing build step 'Make'

Here is, just in case, the .pro file



QT += core gui sql

TARGET = my_project
TEMPLATE = app


SOURCES += main.cpp\
main_window.cpp

HEADERS += main_window.h

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