• 8594阅读
  • 3回复

[提问]怎么我编译qt学习之路39时候,出现这么多的错误》。。 [复制链接]

上一主题 下一主题
离线hmilyylimh
 
只看楼主 倒序阅读 楼主  发表于: 2011-05-06
— 本帖被 yfx2003 从 《C++ GUI Qt 4编程》(第2版)专栏 移动到本区(2011-05-16) —
1.   listwidget.cpp
#include <QHBoxLayout>
#include <QListWidget>
#include <QListWidgetItem>
#include <QLabel>
#include "listwidget.h"

ListWidget::ListWidget(QWidget * parent)
    :QWidget(parent)
{
    label =new QLabel;
    label->setFixedWidth(70);
    QListWidget *list = new QListWidget(this);
    list->addItem(QListWidgetItem(QIcon(:/images/line.png),
              tr("Line")));
    list->addItem(QListWidgetItem(QIcon(:/images/rect.png),
              tr("Rectangle")));
    list->addItem(QListWidgetItem(QIcon(:/images/oval.png),
              tr("Oval")));
    list->addItem(QListWidgetItem(QIcon(:/images/tri.png),
              tr("Triangle")));

    QHBovLayout * layout=new QHBoxLayout;
    layout->addWidget(label);
    layout->addWidget(list);
    setLayout(layout);
    
    connect(list,SIGNAL(currentTextChanged(QString)),
        label,SLOT(setText(QString)));
}


2.  listwidget.h

#ifndef LISTWIDGET_H
#define LISTWIDGET_H

#include <QtGui>
#include <QLabel>
#include <QListWidget>
#include <QListWidgetItem>
#include <QHBoxLayout>

class QLabel;
class QListWidget;
class QHBoxLayout;

class ListWidget : public QWidget
{
public:
    ListWidget(QWidget * parent=0);

private:
    QLabel      * label;
    QListWidget * list;
    QHBovLayout * layout;
};

#endif //LISTWIDGET_H

3.  main.cpp

#include <QtGui>
#include "listwidget.h"

int main(int argc,char **argv)
{
    QApplication app(argc,argv);
    ListWidget lw;
    lw.resize(400,200);
    lw.show();
    return app.exec();
}

4.listwidget.qrc
<!DOCTYPE RCC><RCC version="1.0">
<qresource>
     <file>images/line.png</file>
     <file>images/rect.png</file>
     <file>images/oval.png</file>
     <file>images/tri.png</file>
</qresource>
</RCC>



5.报错信息为:
hmily@xtu:~/文档/24hours_leaar_qt/listwidget_5.6$ make
g++ -c -pipe -O2 -Wall -W -D_REENTRANT -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -I/usr/local/Trolltech/Qt-4.7.2/mkspecs/linux-g++ -I. -I/usr/local/Trolltech/Qt-4.7.2/include/QtCore -I/usr/local/Trolltech/Qt-4.7.2/include/QtGui -I/usr/local/Trolltech/Qt-4.7.2/include -I. -I. -o listwidget.o listwidget.cpp
In file included from listwidget.cpp:5:
listwidget.h:22: error: ISO C++ forbids declaration of ‘QHBovLayout’ with no type
listwidget.h:22: error: expected ‘;’ before ‘*’ token
listwidget.cpp: In constructor ‘ListWidget::ListWidget(QWidget*)’:
listwidget.cpp:13: error: expected primary-expression before ‘(’ token
listwidget.cpp:13: error: expected primary-expression before ‘(’ token
listwidget.cpp:13: error: expected primary-expression before ‘:’ token
listwidget.cpp:15: error: expected primary-expression before ‘(’ token
listwidget.cpp:15: error: expected primary-expression before ‘(’ token
listwidget.cpp:15: error: expected primary-expression before ‘:’ token
listwidget.cpp:17: error: expected primary-expression before ‘(’ token
listwidget.cpp:17: error: expected primary-expression before ‘(’ token
listwidget.cpp:17: error: expected primary-expression before ‘:’ token
listwidget.cpp:19: error: expected primary-expression before ‘(’ token
listwidget.cpp:19: error: expected primary-expression before ‘(’ token
listwidget.cpp:19: error: expected primary-expression before ‘:’ token
listwidget.cpp:22: error: ‘QHBovLayout’ was not declared in this scope
listwidget.cpp:23: error: invalid use of member (did you forget the ‘&’ ?)
listwidget.cpp:23: error: base operand of ‘->’ is not a pointer
listwidget.cpp:24: error: invalid use of member (did you forget the ‘&’ ?)
listwidget.cpp:24: error: base operand of ‘->’ is not a pointer
listwidget.cpp:25: error: no matching function for call to ‘ListWidget::setLayout(<unresolved overloaded function type>)’
/usr/local/Trolltech/Qt-4.7.2/include/QtGui/qwidget.h:546: note: candidates are: void QWidget::setLayout(QLayout*)
make: *** [listwidget.o] 错误 1

6.请各位大侠指点迷津吧...应付我这种初学者大家应该可以很快看出问题来的吧,只不过我经验尚浅,还检查不出什么错误,还请各位帮帮忙...想实现的图片为:
[ 此帖被hmilyylimh在2011-05-06 08:15重新编辑 ]
离线dbzhang800

只看该作者 1楼 发表于: 2011-05-06
认真检查拼写 QHBovLayout
离线hmilyylimh
只看该作者 2楼 发表于: 2011-05-06
还得谢谢1楼的提醒,帮我检查了其中一个错误,还有一点就是:
一定不要忘记了QIcon的分号,这个错误导致我检查类很久
还是谢谢您了》。。
离线ppdayz

只看该作者 3楼 发表于: 2011-05-06
可以去看看[C ++.GUI.Qt.4编程(第二版)] 很不错的一本书,大多数例子都还有源代码,qt学习之路也是参考这本书的
快速回复
限100 字节
 
上一个 下一个