这段代码到底错在哪里?

songhuirong1 2012-05-16 10:28:36
1、colornamesdialog.h文件:
#ifndef COLORNAMESDIALOG_H
#define COLORNAMESDIALOG_H

#include <QtGui/QDialog>

class QStringListModel;
class QSortFilterProxyModel;
class QListView;
class QLabel;
class QLineEdit;
class QComboBox;

class ColorNamesDialog : public QDialog
{
Q_OBJECT

public:
ColorNamesDialog(QWidget *parent = 0);
~ColorNamesDialog();
private:
QStringListModel *sourceModel;
QSortFilterProxyModel *proxyModel;
QListView *listView;
QLabel *filterLabel;
QLineEdit *lineEdit;
QLabel *patternSyntaxLabel;
QComboBox *comboBox;
};

#endif // COLORNAMESDIALOG_H
2、colornamesdialog.cpp文件:
#include <QtGui>
#include "colornamesdialog.h"

ColorNamesDialog::ColorNamesDialog(QWidget *parent)
: QDialog(parent)
{
sourceModel = new QStringListModel(this);
sourceModel->setStringList(QColor::colorNames());
proxyModel = new QSortFilterProxyModel(this);
proxyModel->setSourceModel(sourceModel);
proxyModel->setFilterKeyColumn(0);
listView = new QListView;
listView->setModel(proxyModel);

filterLabel = new QLabel(tr("&Filter"));
lineEdit = new QLineEdit;
patternSyntaxLabel = new QLabel(tr("&Pattern syntax"));
comboBox = new QComboBox;
comboBox->addItem(tr("Regular expressino"), QRegExp::RegExp);
comboBox->addItem(tr("Wildcard"), QRegExp::Wildcard);
comboBox->addItem(tr("Fixed string"), QRegExp::FixedString);

QGridLayout *gridLayout = new QGridLayout;
gridLayout->addWidget(listView, 0, 0, 1, 2);
gridLayout->addWidget(filterLabel, 1, 0);
gridLayout->addWidget(lineEdit, 1, 1);
gridLayout->addWidget(patternSyntaxLabel, 2, 0);
gridLayout->addWidget(comboBox, 2, 1);
setLayout(gridLayout);
}

ColorNamesDialog::~ColorNamesDialog()
{

}
3、main.cpp文件:
#include <QtGui/QApplication>
#include "colornamesdialog.h"

int main(int argc, char *argv[])
{
QApplication a(argc, argv);
ColorNamesDialog w;
w.show();

return a.exec();
}
以上这段代码,编译的时候出现一些错误。不知是何原因。
c:\QtSDK\Desktop\Qt\4.7.4\mingw\include\QtGui\QtGui:78: In file included from c:\QtSDK\Desktop\Qt\4.7.4\mingw\include\QtGui/QtGui:78,
F:\Qt_Workspace\ColorNamesDialog\colornamesdialog.cpp:1: from colornamesdialog.cpp:1:
c:\QtSDK\Desktop\Qt\4.7.4\mingw\include\QtGui\qtreewidget.h:260: 错误:redefinition of 'class QListView'
c:\QtSDK\Desktop\Qt\4.7.4\mingw\include\QtGui\qlistview.h:58: 错误:previous definition of 'class QListView'
后面还有一堆错误,都是关于QListView的错误。请问这是什么原因呀?实在不解。
...全文
205 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
songhuirong1 2012-05-18
  • 打赏
  • 举报
回复
不好意思呀。折腾了半天,原来是我的Qt Creator编译器出了问题,我把它卸载了然后重装,就ok了。
songhuirong1 2012-05-17
  • 打赏
  • 举报
回复
编译能通过的版本是Qt Creator1.0.0 Baseed on Qt4.5.0,通不过的是Qt4.7的吧,具体的我回去再看看。
songhuirong1 2012-05-17
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 的回复:]
编译能通过的版本是Qt Creator1.0.0 Baseed on Qt4.5.0,通不过的是Qt4.7的吧,具体的我回去再看看。
[/Quote]
大大的悲剧。我把同一份代码在Qt Creator2.3.0 Baseed on Qt4.7.4,报的还是同样的错误。真的无语了。哎。不管它了,这种问题我们是解决不了了,得要Qt的研发人员才能搞定了。
shen_wei 2012-05-17
  • 打赏
  • 举报
回复
说下 Qt creator 的版本。。。
  • 打赏
  • 举报
回复
发错了……
[Quote=引用 6 楼 的回复:]

.pp 没有包含头文件, 只是在.h中声明了 还要包含 要不然编译器肯定不过
[/Quote]
  • 打赏
  • 举报
回复
.pp 没有包含头文件, 只是在.h中声明了 还要包含 要不然编译器肯定不过
songhuirong1 2012-05-17
  • 打赏
  • 举报
回复
见鬼了。换了个Qt Creator编译,它居然能运行起来,没报编译错误。这是何解呢?难道这是Qt Creator的各个版本不兼容?就算如此,也不应该报这种错误呀。
songhuirong1 2012-05-17
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 的回复:]
错误提示是QListView被重定义了
[/Quote]
我不知道我到底哪里重定义了QListView,这究竟是为何呢?
songhuirong1 2012-05-17
  • 打赏
  • 举报
回复
[Quote=引用 10 楼 的回复:]
别纠结了,你回去重新编译下也许就没问题了,QtCreator经常会出现些莫名其妙的问题,然后重新编译工程就解决了。
[/Quote]
恩。的确是这样的,Qt Creator在编译的时候经常出一些莫名其妙的问题,不知道这是不是Qt Creator的bug,还有就是Qt Creator的调试功能很不方便,比起visual studio来差远了。所以我很少用Qt Creator调试程序,基本都是自己打Log来调试程序的。真是费劲啦。
xiebin133 2012-05-17
  • 打赏
  • 举报
回复
别纠结了,你回去重新编译下也许就没问题了,QtCreator经常会出现些莫名其妙的问题,然后重新编译工程就解决了。
wangxkww 2012-05-16
  • 打赏
  • 举报
回复
单看错误提示如楼上所说,但是我把代码拷贝到我机器上编译运行没有问题,我用是的Qt Library 4.7.3,不过感觉这个和类库版本关系也不大吧……o(╯□╰)o
如此美丽的你 2012-05-16
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 的回复:]

错误提示是QListView被重定义了
[/Quote]
恩!!!!
开发者说 2012-05-16
  • 打赏
  • 举报
回复
错误提示是QListView被重定义了

16,216

社区成员

发帖
与我相关
我的任务
社区描述
Qt 是一个跨平台应用程序框架。通过使用 Qt,您可以一次性开发应用程序和用户界面,然后将其部署到多个桌面和嵌入式操作系统,而无需重复编写源代码。
社区管理员
  • Qt
  • 亭台六七座
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧