qwt的错误:QWidget:必须在QPaintDevice之前构造一个QApplication

时间:2014-12-06 23:11:54

标签: c++ macos qt qwt

晚上好,

  • system:mac OSX 10.10.1
  • Qt 5.3.2(通过自制软件)
  • qwt 6.1.1(通过自制软件)
  • Qt Creator 3.2.1

我使用了这个教程http://codingexodus.blogspot.de/2013/01/getting-started-with-qwt.html,并将此[http://de.wikibooks.org/wiki /Qt_für_C%2B%2B-Anfänger:_Qwt_nutzen 2作为起点。

这里qwt用于main.cpp:

#include <qwt_plot_curve.h>
#include <qwt_plot.h>
#include <qapplication.h>

int main(int argc, char **argv)
{
    QApplication a(argc, argv);
    double x[101];
    double y[101];

    for ( int i = 0; i < 101; i++ ) {
        x[i] =  i / 10.0;
        y[i] = sin(x[i]);
    }

    QwtPlot plot;
    QwtPlotCurve *curve = new QwtPlotCurve();
    curve->setRawSamples(x, y, 101);
    curve->attach(&plot);
    plot.show();
    return a.exec();
}

当我尝试(通过复制和粘贴以进行测试时,如果我正确地包含了库),我保持接收的两个站点的代码

  

QWidget:必须在QPaintDevice之前构建QApplication

好的,所以我应该在创建Widget之前创建一个Application。 但是,为了安全起见,我决定测试将qwt部分放入mainwindow .cpp文件中。但仍然没有成功。

在应用程序输出下方。似乎qwt和qt之间存在一些冲突...(当我不使用qwt时不会出现。)

Starte /Users/axel/Programmierung/Qt/Qwt2/build-Qwt2-Desktop-Debug/Qwt2.app/Contents/MacOS/Qwt2...
objc[6955]: Class QCocoaPageLayoutDelegate is implemented in both /usr/local/lib/QtGui.framework/Versions/4/QtGui and /usr/local/Cellar/qt5/5.3.2/lib/QtPrintSupport.framework/Versions/5/QtPrintSupport. One of the two will be used. Which one is undefined.
objc[6955]: Class QCocoaPrintPanelDelegate is implemented in both /usr/local/lib/QtGui.framework/Versions/4/QtGui and /usr/local/Cellar/qt5/5.3.2/lib/QtPrintSupport.framework/Versions/5/QtPrintSupport. One of the two will be used. Which one is undefined.
objc[6955]: Class QCocoaApplicationDelegate is implemented in both /usr/local/lib/QtGui.framework/Versions/4/QtGui and /usr/local/Cellar/qt5/5.3.2/plugins/platforms/libqcocoa.dylib. One of the two will be used. Which one is undefined.
objc[6955]: Class QNSApplication is implemented in both /usr/local/lib/QtGui.framework/Versions/4/QtGui and /usr/local/Cellar/qt5/5.3.2/plugins/platforms/libqcocoa.dylib. One of the two will be used. Which one is undefined.
objc[6955]: Class QCocoaMenuLoader is implemented in both /usr/local/lib/QtGui.framework/Versions/4/QtGui and /usr/local/Cellar/qt5/5.3.2/plugins/platforms/libqcocoa.dylib. One of the two will be used. Which one is undefined.
objc[6955]: Class QNSOpenSavePanelDelegate is implemented in both /usr/local/lib/QtGui.framework/Versions/4/QtGui and /usr/local/Cellar/qt5/5.3.2/plugins/platforms/libqcocoa.dylib. One of the two will be used. Which one is undefined.
objc[6955]: Class QNSImageView is implemented in both /usr/local/lib/QtGui.framework/Versions/4/QtGui and /usr/local/Cellar/qt5/5.3.2/plugins/platforms/libqcocoa.dylib. One of the two will be used. Which one is undefined.
objc[6955]: Class QNSStatusItem is implemented in both /usr/local/lib/QtGui.framework/Versions/4/QtGui and /usr/local/Cellar/qt5/5.3.2/plugins/platforms/libqcocoa.dylib. One of the two will be used. Which one is undefined.
objc[6955]: Class QNSMenu is implemented in both /usr/local/lib/QtGui.framework/Versions/4/QtGui and /usr/local/Cellar/qt5/5.3.2/plugins/platforms/libqcocoa.dylib. One of the two will be used. Which one is undefined.
QWidget: Must construct a QApplication before a QPaintDevice
Das Programm ist abgestürzt.
/Users/axel/Programmierung/Qt/Qwt2/build-Qwt2-Desktop-Debug/Qwt2.app/Contents/MacOS/Qwt2 ist abgestürzt

qwt2.pro

#-------------------------------------------------
#
# Project created by QtCreator 2014-12-06T23:33:01
#
#-------------------------------------------------

QT       += core gui

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

TARGET = Qwt2
TEMPLATE = app


SOURCES += main.cpp\
        mainwindow.cpp

HEADERS  += mainwindow.h

FORMS    += mainwindow.ui

win32:CONFIG(release, debug|release): LIBS += -L$$PWD/../../../../../../usr/local/Cellar/qwt/6.1.1/lib/release/ -lqwt
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/../../../../../../usr/local/Cellar/qwt/6.1.1/lib/debug/ -lqwt
else:mac: LIBS += -F$$PWD/../../../../../../usr/local/Cellar/qwt/6.1.1/lib/ -framework qwt
else:unix: LIBS += -L$$PWD/../../../../../../usr/local/Cellar/qwt/6.1.1/lib/ -lqwt

INCLUDEPATH += $$PWD/../../../../../../usr/local/Cellar/qwt/6.1.1/lib/qwt.framework/Versions/6/Headers
DEPENDPATH += $$PWD/../../../../../../usr/local/Cellar/qwt/6.1.1/lib/qwt.framework/Versions/6/Headers

的main.cpp

#include "mainwindow.h"
#include <QApplication>

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

    return a.exec();
}

mainwindow.h

#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>

#include <qwt_plot_curve.h>
#include <qwt_plot.h>




namespace Ui {
class MainWindow;
}

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();

private:
    Ui::MainWindow *ui;
};

#endif // MAINWINDOW_H

mainwindow.cpp

#include "mainwindow.h"
#include "ui_mainwindow.h"

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);



    double x[101];
    double y[101];

    for ( int i = 0; i < 101; i++ ) {
        x[i] =  i / 10.0;
        y[i] = sin(x[i]);
    }

    QwtPlot plot;
//    QwtPlotCurve *curve = new QwtPlotCurve();
//    curve->setRawSamples(x, y, 101);
//    curve->attach(&plot);
//    plot.show();





}

MainWindow::~MainWindow()
{
    delete ui;
}

(请注意,我在QwtPlot plot;之前移除评论时会立即复制有关QApplication和QPaintDevice的错误。

2014年12月7日的其他信息 请注意,错误消息提示不同的Qt版本:

objc[8714]: Class QNSMenu is implemented in both /usr/local/lib/QtGui.framework/Versions/4/QtGui and /usr/local/Cellar/qt5/5.3.2/plugins/platforms/libqcocoa.dylib. One of the two will be used. Which one is undefined.

我没有安装Qt4(知情)

假设: Homebrew安装了Qt4。

所以我通过brew info qwt查看了。 答案:==> Dependencies Required: qt ✔

下一步:brew info qt
答:
qt: stable 4.8.6 (bottled), HEAD http://qt-project.org/ /usr/local/Cellar/qt/4.8.6 (2790 files, 122M) * Built from source

好的,所以自制软件为qwt安装了Qt4。

我依稀记得在5.1或5.2中Qt将一些QGui或QApplication内容移动到另一个头...所以如果qwt现在从Qt5中选择一个头(请记住:错误消息说这是未定义的行为)而不是Qt4,可以这解释了错误发生的原因?

好的,到现在为止,我使用相同的源代码打开了一个新项目,但使用的是qt 4.8.6。 没有错误消息。 也没有情节,但这似乎是另一个问题。

0 个答案:

没有答案