I am trying to build a basic Qt Application with the Meson Build System on my Mac (using macOS Sierra), following the tutorial on http://mesonbuild.com/samples.html.
My meson.build file looks like this:
project('qt5 demo', 'cpp',
default_options : ['cpp_std=c++11'])
qt5_dep = dependency('qt5', modules : ['Core', 'Gui', 'Widgets'])
# Import the extension module that knows how
# to invoke Qt tools.
qt5 = import('qt5')
prep = qt5.preprocess(moc_headers : 'mainWindow.h',
ui_files : 'mainWindow.ui')
executable('qt5app',
sources : ['main.cpp', 'mainWindow.cpp', prep],
dependencies : qt5_dep,
cpp_args : '-std=c++11')
I have a small test program consisting of only four files: main.cpp, mainwindow.h, mainwindow.cpp, and mainwindow.ui.
The source code is as follows.
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>
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);
}
MainWindow::~MainWindow()
{
delete ui;
}
The program compiles and executes as expected when I use qmake as a build system using the following qmake-file:
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = QtDesigner
TEMPLATE = app
SOURCES += main.cpp\
mainwindow.cpp
HEADERS += mainwindow.h
FORMS += mainwindow.ui
When I execute
meson build
it works fine, except for the warning:
WARNING: rcc dependencies will not work reliably until this upstream issue is fixed:
https://bugreports.qt.io/browse/QTBUG-45460
It also compiles without errors, when I switch to the build directory and call
ninja
but when I execute the program I get the following error:
dyld: Library not loaded: #rpath/QtCore.framework/Versions/5/QtCore
Referenced from:
/Users/<myname>/code/C++/QtDesignerCode/build/./qt5app
Reason: image not found
Abort trap: 6
It seems like the linker cannot find the libraries? Which is weird, as in Qt Creator (using qmake) the source code compiles fine.
Thanks in advance for any help.
Do the following in the build dir
mesonconf -Dcpp_std=c++11
or, set the default language version in your meson.build file
Related
I am trying follow the instructions published here:
https://www.linux.org/threads/c-tutorial-create-qt-applications-without-qtcreator.18409/
but in a PC running Windows 10, to build a Qt application createdwith the Atom editor. I have this 3 files in my project right now:
qt_main.cpp
#include <QtWidgets>
#include "mainwidget.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWidget w;
w.show();
return a.exec();
}
mainwidget.h
#ifndef MAINWIDGET_H
#define MAINWIDGET_H
#include <QWidget>
class QPushButton;
class QTextBrowser;
class MainWidget : public QWidget
{
Q_OBJECT
public:
explicit MainWidget(QWidget *parent = 0);
~MainWidget();
private:
QPushButton* button_;
QTextBrowser* textBrowser_;
};
#endif // MAINWIDGET_H
mainwidget.cpp
#include <QtWidgets>
#include "mainwidget.h"
MainWidget::MainWidget(QWidget *parent) : QWidget(parent)
{
button_ = new QPushButton(tr("Push Me!"));
textBrowser_ = new QTextBrowser();
QGridLayout *mainLayout = new QGridLayout;
mainLayout->addWidget(button_,0,0);
mainLayout->addWidget(textBrowser_,1,0);
setLayout(mainLayout);
setWindowTitle(tr("Connecting buttons to processes.."));
}
MainWidget::~MainWidget()
{
delete button_;
delete textBrowser_;
}
I execute this commands, in sequence:
qmake -project
add `QT += widgets` to the qt_main.pro file generated
qmake qt_main.pro
make
After that, the EXE file is generated without error, but when I try run it, I got the error:
"The procedure entry point _ZN10QArrayData10deallocateEPS_jj could not be located in the dynamic link library etc."
I try follow the suggested on the comments for the question:
QArrayData error, linking Qt libraries with CMake
and check my PATH. right now, the only directory containing qt DLLs is the one:
C:\Qt\Qt5.14.0\5.14.0\mingw73_64\bin
(this directory was createwd by the Qt offline installer).
Anyone can give a hint of how to solve this issue?
I am trying to make a app using qt 5.4.1(and qwt 6.1.2).Here is my environment:
Windows 7 x64
visual studio 2012
Qt5.4.1 static
qwt6.1.2
and I have built qwt with my Qt static libs successfully.
I creat a widget class inherited from QwtPlot,and I creat a mainWindow which has a object of that widget. Then I build the project.
However,there is a runtime error:QWidget: Must construct a QApplication before a QWidget.
This is my widget class inherited from QwtPlot:
#pragma once
#include <QWT/qwt_plot.h>
#include <QWT/qwt_plot_curve.h>
class DrawWidget: public QwtPlot
{
public:
DrawWidget(QWidget *parent );
~DrawWidget(void);
};
DrawWidget::DrawWidget(QWidget *parent )
: QwtPlot( parent ),
carve(NULL)
{
}
And the follow is my mainWindow class:
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include "DrawWidget.h"
#include <QtWidgets/QMainWindow>
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
MainWindow(QWidget *parent = 0);
~MainWindow();
private:
DrawWidget *drawWidget;
};
#endif // MAINWINDOW_H
MainWindow::MainWindow(QWidget *parent)
:QMainWindow(parent)
{
QWidget *widget = new QWidget(this);
this->setCentralWidget(widget);
QHBoxLayout *mainLayout = new QHBoxLayout(widget);
drawWidget = new DrawWidget(widget);
mainLayout->addWidget(drawWidget);
centralWidget()->setLayout(mainLayout);
}
And this is my main.cpp:
#include "mainwindow.h"
#include <QtWidgets/QApplication>
#include <QtPlugin>
Q_IMPORT_PLUGIN(QWindowsIntegrationPlugin);
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.resize(1000,600);
w.show();
return a.exec();
}
I build this project in release version.Any idea? Thank you!
I had the same problem few weeks ago in my case the problem was the additional library. Make sure that you got builds of the additional library debug for debug building and release for release building. Add AdditionalLibraryDebug/bin folder to the Path environment variable when you build Debug Version and AdditionalLibraryRelease/bin when you build Release version (not both in same time)
Good Luck :) i solved my problem on this way. :)
I found this very useful
http://www.itk.org/Wiki/VTK/FAQ#Shared_builds_of_VTK_and_debugging_QVTKWidget_using_Visual_Studio
It happens that libraries depend on the debug version of VTK so you have to build both release and debug and be sure to add the path in the debugging properties.
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.
Qt project suddenly stopped building. So as new just created empty projects based on QDialog or examples. Cleaning, rebuilding not helping.
Log of key errors:
/Users/dmitrytolstov/Workspace/Qt521/5.2.1/clang_64/lib/QtWidgets.framework/Versions/5/Headers/qdialog.h:117:
error: unknown type name 'QDialog'
Q_DISABLE_COPY(QDialog)
/Users/dmitrytolstov/Workspace/Qt521/5.2.1/clang_64/lib/QtWidgets.framework/Versions/5/Headers/qdialog.h:117:
error: C++ requires a type specifier for all declarations
Q_DISABLE_COPY(QDialog)
/Users/dmitrytolstov/Workspace/Qt521/5.2.1/clang_64/lib/QtWidgets.framework/Versions/5/Headers/qdialog.h:117:
error: unknown type name 'QDialog'
/Users/dmitrytolstov/Workspace/CC++/QtStuff/NewDiaproj/dialog.h:10:
error: unknown class name 'QDialog'; did you mean 'Dialog'?
class Dialog : public QDialog
/Users/dmitrytolstov/Workspace/CC++/QtStuff/NewDiaproj/dialog.h:10:
error: base class has incomplete type
class Dialog : public QDialog
/Users/dmitrytolstov/Workspace/CC++/QtStuff/NewDiaproj/main.cpp:8:
error: no member named 'show' in 'Dialog'
w.show();
7 errors generated.
make: *** [main.o] Error 1
18:46:36: Process «/usr/bin/make» exit with code 2.
Seems like something happened with qdialog.h or something. By the way project on QMainWindow works fine. I didn't do anything. Tried to reopen QtCreator, reboot computer.
I use Mac OS X and Qt 5.2.1
Any example provided by QtCreator or empty project based on QDialog. For example:
dialog.cpp:
#include "dialog.h"
Dialog::Dialog(QWidget *parent) :
QDialog(parent)
{
}
Dialog::~Dialog()
{
}
dialog.h
#ifndef DIALOG_H
#define DIALOG_H
#include <QDialog>
class Dialog : public QDialog
{
Q_OBJECT
public:
explicit Dialog(QWidget *parent = 0);
~Dialog();
};
#endif // DIALOG_H
main.cpp
#include "dialog.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Dialog w;
w.show();
return a.exec();
}
NewDiaproj.pro
#-------------------------------------------------
#
# Project created by QtCreator 2014-04-20T19:31:45
#
#-------------------------------------------------
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = NewDiaproj
TEMPLATE = app
SOURCES += main.cpp\
dialog.cpp
HEADERS += dialog.h
Based on the fact that your files work fine for me on Archlinux with Qt 5.2, I think your QDialog file in the Qt installation got corrupted by some accidental or "vis major" action.
Reinstall it cleanly and then it should just work.
I must be missing a basic concept with headers and includes because when I attempt to call even the simplest of a function from a separate source file I get an error:
main.obj:-1: error: LNK2019: unresolved external symbol "void __cdecl
buildDeck(int,int)" (?buildDeck##YAXHH#Z) referenced in function _main
deck.h
#ifndef DECK_H
#define DECK_H
#include <QString>
void buildDeck(int deckSize, int jokers);
struct card
{
QString suit;
QString color;
int rank;
};
#endif // DECK_H
deck.cpp
#include"mainwindow.h"
#include "deck.h"
void buildDeck(int deckSize, int jokers)
{
int blackRed = deckSize-=jokers;
}
main.cpp
#include "mainwindow.h"
#include "deck.h"
#include <QApplication>
#include <QPushButton>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
buildDeck(10,20);
return a.exec();
}
And this gives me an error. However, If I move the function definition from deck.cpp to the bottom of main.cpp, then the application will build.
All of the files are included in the same project, and stored in the same directory.
Other files:
.pro file
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = carddeck
TEMPLATE = app
SOURCES += main.cpp\
mainwindow.cpp \
deck.cpp
HEADERS += mainwindow.h \
deck.h
FORMS += mainwindow.ui
not sure if you need it, but here's mainwindow.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QPushButton>
#include <QTextEdit>
#include <QCheckBox>
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
private slots:
void runButtonClicked();
private:
Ui::MainWindow *ui;
QPushButton *runButton;
QTextEdit * runText;
QCheckBox * betHearts;
QCheckBox * betDiamonds ;
QCheckBox * betClubs;
QCheckBox * betSpades ;
QCheckBox * betFlush ;
QCheckBox * betAllRed;
QCheckBox * betAllBlack ;
};
#endif // MAINWINDOW_H
It looks like the Makefile was not regenerated when you edited the .pro file.
Run qmake and try again.
You could also check if the deck.cpp is compiled or not; is there a deck.o in the build directory ?
yes, some time Makefile file is not updated while you change .pro file. So you have to run qmake.
Follow this steps:
Right click on project Clean / Build menu -> cleanAll
Right click on project Run qmake / Build menu -> runQmake
Right click on project Build / Build menu -> build
Pro Advice:
I don't know but sometime Qt is not updating Makefile. so i recomanded to all whenever you add/removing any resource in project or if any changes occur in your .pro file, just Run qmake and build your project(Running qmake do manually to update the path of project, which help to find the mainwindow.obj file).