c++ - 未安装 QT C++ 模块
问题描述
我是 QT 的新手。我正在编写一个集成到 QT 的演示 C++ 程序。它一直得到模块未安装错误,即使我尝试了互联网帖子中的几个技巧。
我从网站上下载了最新的 QT 包。QT Creator:4.7.0、QT 5.11.1(MSVC 2015、32 位)、Windows 10 PC
感谢任何建议......
这是代码:
//myclass.h
#include <QObject>
#include <QString>
class MyClass : public QObject
{
Q_OBJECT
public:
explicit MyClass(QObject *parent = 0);
Q_INVOKABLE QString sayHello() const;
};
//myclass.cpp
#include "myclass.h"
MyClass::MyClass(QObject *parent): QObject(parent)
{
}
QString MyClass::sayHello() const
{
return "Hello!";
}
//main.cpp
#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QtQml>
#include "QQmlContext"
#include "QQmlEngine"
#include "myclass.h"
int main(int argc, char *argv[])
{
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QGuiApplication app(argc, argv);
qmlRegisterType<MyClass>("com.mycompany.myapplication", 1, 0, "MyClass");
QQmlApplicationEngine engine;
MyClass myClass;
engine.rootContext()->setContextProperty("myClass", &myClass);
engine.load(QUrl(QLatin1String("qrc:/main.qml")));
return app.exec();
}
//main.qml
import QtQuick 2.7
import QtQuick.Controls 2.0
import QtQuick.Layouts 1.0
import com.mycompany.myapplication 1.0
ApplicationWindow {
visible: true
width: 640
height: 480
title: qsTr("Hello World")
Text {
anchors.centerIn: parent
text: myClass.sayHello()
}
}
// myclass.pro
QT += quick
CONFIG += c++11
DEFINES += QT_DEPRECATED_WARNINGS
SOURCES += main.cpp
myclass.cpp
RESOURCES += qml.qrc
QML_IMPORT_PATH =
QML_DESIGNER_IMPORT_PATH =
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target
HEADERS += myclass.h
解决方案
推荐阅读
- ffmpeg - FFMPEG php HLS 和 DASH 转换
- python - 我想根据 pandas 列发送电子邮件
- javascript - 使用 nodejs 库为 google 经销商 api 验证服务帐户时出现问题
- android - 如何使用推送器发送数据类型映射?
- sas - PROC FCMP 返回不正确的字符串长度
- firebase - 上传用户个人资料图片 Firebase - Flutter
- ios - UICollectionViewCompositionalLayout - 部分作为列
- c# - 创建 PDF 适用于 Unity (Windows) 但不适用于 Android 设备
- google-cloud-platform - 如何为免费的谷歌云功能缓存一个低于 5MB 的配置?
- java - hamcrest-core: jar:1.4-atlassian-1 无法在 Spring Boot 项目的 MVN 全新安装上解决