一直想静态
编译代码,但是在代码中使用了Chart和QtGraphicalEffects模块。Chart模块无法在别的电脑运行,QtGraphicalEffects无法编译。
因为我想使用Control 2,所以我用的Qt 5.8,顺便吐槽一句Qt 5.7的Control 2的BUG实在有点多,并且莫名其妙。
工程
文件代码如下:
- QT += qml quick
- QT += core gui widgets
- QT += charts
- CONFIG += c++11
- SOURCES += main.cpp
- RESOURCES += qml.qrc
- # Additional import path used to resolve QML modules in Qt Creator's code model
- QML_IMPORT_PATH =
- # Additional import path used to resolve QML modules just for Qt Quick Designer
- QML_DESIGNER_IMPORT_PATH =
- # The following define makes your compiler emit warnings if you use
- # any feature of Qt which as been marked deprecated (the exact warnings
- # depend on your compiler). Please consult the documentation of the
- # deprecated API in order to know how to port your code away from it.
- DEFINES += QT_DEPRECATED_WARNINGS
- # You can also make your code fail to compile if you use deprecated APIs.
- # In order to do so, uncomment the following line.
- # You can also select to disable deprecated APIs only up to a certain version of Qt.
- #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
- # Default rules for deployment.
- qnx: target.path = /tmp/${TARGET}/bin
- else: unix:!android: target.path = /opt/${TARGET}/bin
- !isEmpty(target.path): INSTALLS += target
chart需要用到
Widget里面的东西,所以必须添加Widget,并且在main.c的代码里面要app类型为QApplication
main.c文件代码如下:
- #include <QQmlApplicationEngine>
- #include <QtWidgets/QApplication>
- #include <QtPlugin>
- Q_IMPORT_PLUGIN(QWindowsIntegrationPlugin)
- int main(int argc, char *argv[])
- {
- QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
- QApplication app(argc, argv);
- QQmlApplicationEngine engine;
- engine.load(QUrl(QLatin1String("qrc:/main.qml")));
- return app.exec();
- }
main.qml中的代码
- import QtQuick 2.7
- import QtQuick.Controls 2.1
- import QtQuick.Layouts 1.0
- import QtCharts 2.1
- import QtGraphicalEffects 1.0
- ApplicationWindow {
- visible: true
- width: 640
- height: 480
- title: qsTr("Hello World")
- SwipeView {
- id: swipeView
- anchors.fill: parent
- currentIndex: tabBar.currentIndex
- Page {
- Button{
- anchors.centerIn: parent
- text:"First page"
- layer.enabled: hovered
- layer.smooth: true
- layer.effect: DropShadow {
- color: activeFocus ? "#330066ff" : "#aaaaaa"
- verticalOffset: 3
- horizontalOffset: 3
- radius: 6
- samples: 12
- spread: 0.7
- }
- }
- }
- Page {
- ChartView {
- title: "Line"
- anchors.fill: parent
- antialiasing: true
- LineSeries {
- name: "LineSeries"
- XYPoint { x: 0; y: 0 }
- XYPoint { x: 1.1; y: 2.1 }
- XYPoint { x: 1.9; y: 3.3 }
- XYPoint { x: 2.1; y: 2.1 }
- XYPoint { x: 2.9; y: 4.9 }
- XYPoint { x: 3.4; y: 3.0 }
- XYPoint { x: 4.1; y: 3.3 }
- }
- }
- }
- }
- footer: TabBar {
- id: tabBar
- currentIndex: swipeView.currentIndex
- TabButton {
- text: qsTr("First")
- }
- TabButton {
- text: qsTr("Second")
- }
- }
- }
静态编译所用的命令符:
configure.bat -confirm-license -opensource -platform win32-g++ -mp -debug-and-release -static -prefix "D:\Qt\5.8.0_MinGW_static" -qt-zlib -qt-libpng -qt-libjpeg -opengl desktop -qt-freetype -no-qml-debug -no-angle -nomake tests -nomake examples -skip qtwebengine -skip qtwebview
这个命令符是什么意思,我只能看懂-skip qtwebengine -skip qtwebview?会不会是静态编译包在制作的时候
没有把Chart和QtGraphicalEffects编译进去?
还有一个
问题,在Qt 5.8默认的编译器下,DEBUG会出现如下的问题,Release版本则不会:
ASSERT failure in void QtFontFamily::ensurePopulated(): "SimSun", file text\qfontdatabase.cpp, line 425
Invalid parameter passed to C runtime function.
Invalid parameter passed to C runtime function.
我在网上找了相关的信息,有人遇到了,但是解决办法我没有看懂。链接如下:
http://blog.csdn.net/zyzhaojun/article/details/52491041