Good evening,
- system: mac OSX 10.10.1
- Qt 5.3.2 (via homebrew)
- qwt 6.1.1 (via homebrew)
- Qt Creator 3.2.1
I have used this tutorial http://codingexodus.blogspot.de/2013/01/getting-started-with-qwt.html and this one [http://de.wikibooks.org/wiki/Qt_für_C%2B%2B-Anfänger:_Qwt_nutzen2 as a starting point.
Here qwt is used in 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();
}
When I tried (via copy and paste for test purposes if I have the library included correctly) the codes from both sites I kept receiving
QWidget: Must construct a QApplication before a QPaintDevice
Ok, so I should create a Application before I create a Widget. However, to be on the safe side, I decided to test puting the qwt part into the mainwindow .cpp file. Still, no success.
Below the application output. Seems like there is some conflict between qwt and qt... (does not appear, when I do not use 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;
}
(note that the error regarding QApplication and QPaintDevice is replicated as soon as I remove the comment before QwtPlot plot;
.
Additional info from 07.12.2014 Please note that the error messages hint at a different Qt version:
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.
I did not install Qt4 (knowingly)
Hypothesis: Homebrew installed Qt4.
So i checked via brew info qwt
.
Answer: ==> Dependencies
Required: qt ✔
So next step: brew info qt
Answer:
qt: stable 4.8.6 (bottled), HEAD
http://qt-project.org/
/usr/local/Cellar/qt/4.8.6 (2790 files, 122M) *
Built from source
Ok, so homebrew installs Qt4 for qwt.
I vaguely remember that in 5.1 or 5.2 Qt moved some QGui or QApplication stuff to another header... So if qwt now chooses a header from Qt5 (remember: the error message said this is undefined behaviour) instead of Qt4, could this explain why the error occurs?
Ok, by now I opened a new project with the same source code but using qt 4.8.6. No error messages. Also no plot, but this seems to be another problem.