• 5384阅读
  • 3回复

做这个Graphics View Framework实验时,老是显示这么多的错误...请大侠帮帮小弟... [复制链接]

上一主题 下一主题
离线hmilyylimh
 
只看楼主 倒序阅读 楼主  发表于: 2011-05-05
— 本帖被 XChinux 从 《C++ GUI Qt 4编程》(第2版)专栏 移动到本区(2011-05-05) —
1.   graphicsview.h 头文件
#ifndef GRAPHICSVIEW_H
#define GRAPHICSVIEW_H
#include <QtGui/QWidget>
#include <QGraphcsView>

class QGraphicsScene;
class DrawApp;
class QGraphcsView;
class QGraphcs;
class QPainter;

class DrawApp : public QWidget
{
    Q_OBJECT

public:
    DrawApp(QWidget *parent=0);

private:
    QGraphicsScene * scene;
    DrawApp        * da;
    QGraphcsView   * view;
     QPainter painter;

protected:
    void paintEvent(QPaintEvent *event);
};

#endif


2.   graphicsview.cpp文件
#include <QGraphcsView>
#include <QApplication>
#include <QGraphicsScene>
#include <QPainter>
#include <QPaintEvent>
#include <DrawApp>
#include "graphicsview.h"


DrawApp::DrawApp(QWidget *parent)
    :QWidget(parent)
{

}

void DrawApp::paintEvent(QPaintEvent *event)
{
    QPainter painter(this);
    painter.drawLine(10,10,150,300);
}

int main(int argc,char **argv)
{
    QApplication a(argc,argv);
    QGraphicsScene *scene=new QGraphicsScene;
    //创建了一个 QGraphicsScene 作为场
    scene->addLine(10,10,150,300);//在 scene 中添加了一条直线
    QGraphcsView *view=new QGraphcsView(scene);
    //创建一个 QGraphicsView 对象进行观察
    view->resize(500,500);
    view->setWindowTitle("Graphics View");
    view->show();
    DrawApp *da=new DrawApp;
    da->resize(500,500);
    da->setWindowTitle("QWidget");
    da->show();
    return a.exec();
}


3. 然后编译出来就报错,报错为:
hmily@xtu:~/文档/24hours_leaar_qt/graphicsview_5.5$ 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 graphicsview.o graphicsview.cpp
graphicsview.cpp:1:24: error: QGraphcsView: 没有那个文件或目录
graphicsview.cpp:6:19: error: DrawApp: 没有那个文件或目录
graphicsview.cpp:16: warning: unused parameter ‘event’
graphicsview.cpp: In function ‘int main(int, char**)’:
graphicsview.cpp:28: error: invalid use of incomplete type ‘struct QGraphcsView’
graphicsview.h:8: error: forward declaration of ‘struct QGraphcsView’
graphicsview.cpp:30: error: invalid use of incomplete type ‘struct QGraphcsView’
graphicsview.h:8: error: forward declaration of ‘struct QGraphcsView’
graphicsview.cpp:31: error: invalid use of incomplete type ‘struct QGraphcsView’
graphicsview.h:8: error: forward declaration of ‘struct QGraphcsView’
graphicsview.cpp:32: error: invalid use of incomplete type ‘struct QGraphcsView’
graphicsview.h:8: error: forward declaration of ‘struct QGraphcsView’
make: *** [graphicsview.o] 错误 1

4.还请各位帮忙解决解决.....................我想实现的图像为:
离线浪漫天使
只看该作者 1楼 发表于: 2011-05-05
第一,建议你了解一些c++的语法,比如成员变量与临时变量是什么东西。
第二;你的main函数 出来了2个窗口,不知道你想要的是哪个?view的还是da的?
第三:你的对错误信息要认真观察,比如Qt中的类名叫QGraphicsView 而你写成了QGraphcsView 所以会报错
第四:#include <DrawApp> 这个东西你想表示什么意思呢?
[ 此帖被浪漫天使在2011-05-05 08:14重新编辑 ]
离线hmilyylimh
只看该作者 2楼 发表于: 2011-05-05
嗯,刚才才看见帖子,按照您的方式改了之后果然出现了结果...谢谢...但是我还想问一下,就是说,单纯的看C++语法的话,可我根本看不进去,我就是想在一边操作一边出结果的过程中才能对那些东西认识清楚...有什么建议没啊?
离线downstairs

只看该作者 3楼 发表于: 2011-05-05
静下心来。看不懂。多看几遍。
喜爱编程的猫头鹰
快速回复
限100 字节
 
上一个 下一个