我正在尝试构建一个非常基本的Qt5应用程序,它使用QtQuick 2作为UI语言,并使用GNU Makefile构建。这意味着,我不想使用javascript,而是加载QML布局并在C ++中指定信号和插槽。但是,这是我的问题:
请在下面找到我的第一次尝试:
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();
}
生成文件
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 from 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)