本文主要是介绍将Qt imports目录路径作为参数传递,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
我过去使用环境变量指定imports目录路径,在看过qmlscene的代码后,我能够将imports路径作为参数传递给我的程序。下面是我的完整代码:
#include <QtQml>
#include <QtQuick/QQuickView>
#include <QtCore/QString>
#include <algorithm>
#ifdef QT_WIDGETS_LIB
#include <QtWidgets/QApplication>
#else
#include <QtGui/QGuiApplication>
#endif#ifdef QT_WIDGETS_LIB
#define Application QApplication
#else
#define Application QGuiApplication
#endif
QCoreApplication* createApplication(int & argc, char * argv[]) {for (int i = 1; i < argc; ++i) {if (!qstrcmp(argv[i], "-no-gui")) {return new QCoreApplication(argc, argv);}}return new QApplication(argc, argv);
}
int main(int argc, char *argv[])
{if ((argc != 3) || qstrcmp(argv[1], "-I")) {qWarning("Error: You must pass the location of plugins as one argument, e.g. -I ..\imports");return -1;}QDir folder(argv[2]);QString imports_dir_path;
这篇关于将Qt imports目录路径作为参数传递的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!