QCoreApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);

132 阅读1分钟
  1. 在QT应用程序中,QML模块的初始化通常在main()函数中进行。我们需要包含必要的头文件,并调用QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);和QCoreApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);,以确保应用程序能够正确处理高分辨率显示器。
    cpp
    include
    include
    include
    int main(int argc, char *argv[])
    {
    QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
    QCoreApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
    QGuiApplication app(argc, argv);
    QQmlApplicationEngine engine;
    __ 注册QML模块
    registerTypes();
    const QUrl url(QStringLiteral(qrc:_main.qml));
    QObject::connect(&engine, &QQmlApplicationEngine::objectCreated, [url](QObject *obj, const QUrl &objUrl) {
    if (!obj && url == objUrl)
    QCoreApplication::exit(-1);
    });
    engine.load(url);
    return app.exec();
    www.laipuhuo.com/articlePage… www.laipuhuo.com/articlePage… www.laipuhuo.com/articlePage… www.laipuhuo.com/articlePage… www.laipuhuo.com/01FAA7E8E45… www.laipuhuo.com/01FBA59F88E… www.laipuhuo.com/01FFCBE344D… www.laipuhuo.com/02054AB7DF9… www.laipuhuo.com/02054AB7DF9… www.laipuhuo.com/0208ca5e75d… }
  2. QML模块的注册
    在QML模块注册过程中,我们需要使用qmlRegisterType()函数来注册自定义的QML类型。这个函数需要提供四个参数,模块名、版本号、组件类名和可选的元对象名称。
    cpp
    __ 在某个头文件中
    void registerTypes()