c++ - Buidling Qt5 & QtQuick 2 application with GNU Make -
i trying build basic qt5 application uses qtquick 2 ui-language , build using gnu makefile. means, don't want use javascript, load qml layout , specify signals , slots in c++. however, here questions:
- what's best way load qml layout , access its' elements?
- how build such application directly gnu make instead of using qmake generate makefile?
please find first attempts below:
qml/main.qml
import qtquick 2.5 import qtquick.controls 1.4 import qtquick.dialogs 1.2 rectangle { width: 360 height: 360 text { text: qstr("hello world") anchors.centerin: parent } mousearea { anchors.fill: parent onclicked: { qt.quit(); } } }
src/main.cpp
#include <qapplication> #include <qqmlapplicationengine> #include <sqlite3.h> int main(int argc, char* argv[]) { qapplication app(argc, argv); qqmlapplicationengine engine; engine.load(qurl(qstringliteral("qrc:/main.qml"))); return app.exec(); }
makefile
cc = /usr/bin/g++ moc = moc-qt5 cflags = -wall -pedantic -std=c++0x -d_reentrant \ -dqt_no_debug -dqt_gui_lib -dqt_core_lib -dqt_shared target = yarott incpath = -i. -i/usr/include -i/usr/include/qt -i/usr/include/qt/qtgui \ -i/usr/include/qt/qtcore -i/usr/lib/qt/mkspecs/linux-g++ ldflags = -l/usr/lib -lsqlite3 -lqt5gui -lqt5core -lgl -lpthread srcpath = ./src binpath = ./bin defines = $(shell find $(srcpath) -type f -name '*.h') sources = $(shell find $(srcpath) -type f -name '*.cpp') objects := $(patsubst $(srcpath)/%.cpp, $(binpath)/%.o, $(sources)) moc_sources := $(patsubst $(srcpath)/%.cpp, $(srcpath)/moc_%.cpp, $(sources)) moc_objects := $(patsubst $(binpath)/%.o, $(binpath)/moc_%.o, $(objects)) sources += $(moc_sources) objects += $(moc_objects) all: bin $(target) $(target): $(objects) $(cc) $(cflags) -o $(binpath)/$(target) $(objects) $(ldflags) $(incpath) $(binpath)/%.o: $(srcpath)/%.cpp @mkdir -p "$(@d)" $(cc) $(cflags) -c $< -o $@ $(srcpath)/moc_%.cpp: $(srcpath)/%.h $(moc) $(defines) $(incpath) $< -o $@ # generate cc h via qt's meta object compiler # $(srcpath)/%.moc.cc: $(srcpath)/%.h # $(moc) $(incpath) $< -o $@ # create bin folder bin: mkdir $(binpath) # remove bin folder clean: rm -r $(binpath)
Comments
Post a Comment