• 5750阅读
  • 3回复

新手急问,关于C++ GUI Programming with Qt 4中第五章画图部分 [复制链接]

上一主题 下一主题
离线浪客剑心
 
只看楼主 正序阅读 楼主  发表于: 2009-01-19
— 本帖被 XChinux 执行加亮操作(2009-01-19) —
例子中只给出了,plotter.h和plotter.cpp的源文件,在main数中应该如何进行调用呢?? 请大家帮帮忙,最好附上源码!
离线flykof
只看该作者 3楼 发表于: 2009-04-20
attica大大給的這個是沒錯的吧,我在QT4.5下去執行沒問題呢。
离线benq
只看该作者 2楼 发表于: 2009-04-19
    这个事在QT3平台下运行的,我现在想到QT4下运行,太多错误!
C++ GUI Programming with Qt 4中没这代码,是Qt 3
离线attica

只看该作者 1楼 发表于: 2009-01-20
书附的example源代码中不是有main.c吗?

#include <QtGui>

#include "plotter.h"

void readFlightCurves(Plotter *plotter, const QString &fileName)
{
    QVector<QPointF> data[6];
    double factX = 0.0013;
    double factY[6] = { 0.0008, 0.1, 0.2, 0.2, 0.1, 0.8 };
    double offsY[6] = { +500, -55, +309, +308, 0, 0 };
    int pos[6] = { 3, 6, 7, 8, 9, 10 };
    QFile file(fileName);
    double offsX = 0.0;

    if (file.open(QIODevice::ReadOnly)) {
        QTextStream in(&file);
        while (!in.atEnd()) {
            QString line = in.readLine();
            QStringList coords = line.split(' ',
                                            QString::SkipEmptyParts);
            if (coords.count() >= 6) {
                double x = factX * coords[0].toDouble();
                if (data[0].isEmpty())
                    offsX = x;
                for (int i = 0; i < 6; ++i) {
                    double y = coords[pos].toDouble();
                    data.append(QPointF(x - offsX,
                                          factY * (y - offsY)));
                }
            }
        }
    }

    plotter->setCurveData(0, data[0]);
    plotter->setCurveData(1, data[1]);
    plotter->setCurveData(2, data[2]);
    plotter->setCurveData(3, data[3]);
    plotter->setCurveData(4, data[4]);
    plotter->setCurveData(5, data[5]);
}

int main(int argc, char *argv[])
{
    QApplication app(argc, argv);
    Plotter plotter;
    plotter.setWindowTitle(QObject::tr("Jambi Plotter"));
#if 0
    readFlightCurves(&plotter, ":/in1.txt");
#else
    int numPoints = 100;
    QVector<QPointF> points0;
    QVector<QPointF> points1;
    for (int x = 0; x < numPoints; ++x) {
        points0.append(QPointF(x, uint(qrand()) % 100));
        points1.append(QPointF(x, uint(qrand()) % 100));
    }
    plotter.setCurveData(0, points0);
    plotter.setCurveData(1, points1);

    PlotSettings settings;
    settings.minX = 0.0;
    settings.maxX = 100.0;
    settings.minY = 0.0;
    settings.maxY = 100.0;
    plotter.setPlotSettings(settings);
#endif
    plotter.show();
    return app.exec();
}
快速回复
限100 字节
 
上一个 下一个