'qapplicationapp'在此作用域中尚未声明 linux,QQuickWindow在共享lib自动关闭时在QApplication中显示(示例代码)...

我用qt开发了一个通用接口库。当我点击触摸屏时,我在QPush按钮上的按下效果有问题(此效果在10次点击时出现一次)。

所以我用一个按钮创建了一个基本的qml应用程序,并且按下的效果一直出现。我将qml部分包含到我的库中并将其加载到QQuickWidget中,我对压缩效果也有同样的问题。

所以我只想使用qml。我的主要应用程序是QApplication,我在其中加载了我的库,其中我使用QQmlApplication Engine加载qml文件。然后我通过QQuickWindow展示它。

当我启动我的应用程序时,我看到窗口打开但它自动关闭。我认为我的QApplication没有检测到QML,渲染器循环也没有启动。

我在QT5.5.1的Windows上(MSVC2013,32bit)

主要应用程序的pro文件

QT += core xml widgets qml quick

TARGET = COM_INT

CONFIG += console

CONFIG -= app_bundle

TEMPLATE = app

SOURCES += main.cpp

comint.cpp

HEADERS +=

comint.h

INCLUDEPATH += "$$(My_Workspace)/Modules_Generique/IHM_Soft"

Release{

LIBS += "$$(My_Workspace_build)/IHM_Soft/release/IHM_Soft.lib"

}

Debug{

LIBS += "$$(My_Workspace_build)/IHM_Soft/debug/IHM_Soft.lib"

}

主要应用程序(exe)main.cpp

#include

#include

#include "comint.h"

int main(int argc, char *argv[])

{

QApplication a(argc, argv);

ComInt com;

com.initialize();

return a.exec();

}

ComInt类:源文件comint.cpp

#include "comint.h"

#include "ihmsoft.h"

ComInt::ComInt()

{

}

void ComInt::initialize()

{

this->m_pIHMSoft = new IHMSoft();

}

头文件comint.h

#ifndef COMINT_H

#define COMINT_H

class IHMSoft;

class ComInt

{

public:

ComInt();

void initialize();

private:

IHMSoft *m_pIHMSoft;

};

#endif // COMINT_H

共享库的pro文件

QT += xml widgets core qml quick quickwidgets

CONFIG += c++11

TARGET = IHM_Soft

TEMPLATE = lib

DEFINES += IHM_SOFT_LIBRARY

SOURCES += ihmsoft.cpp

HEADERS += ihmsoft.h

ihm_soft_global.h

RESOURCES +=

rsc.qrc

共享库:源文件him_soft.cpp

#include "ihmsoft.h"

#include

#include

IHMSoft::IHMSoft(){

qputenv("QT_QUICK_CONTROLS_STYLE", "Base");

QQmlApplicationEngine engine;

engine.load(QUrl(QStringLiteral("qrc:/IHM_Soft.qml")));

QList root = engine.rootObjects();

QQuickWindow *window = qobject_cast(root.at(0));

window->show();

}

头文件him_soft.h

#ifndef IHM_SOFT_H

#define IHM_SOFT_H

#include "ihm_soft_global.h"

class IHM_SOFT_SHARED_EXPORT IHM_Soft

{

public:

IHM_Soft();

};

#endif // IHM_SOFT_H

全局文件him_soft_global.h

#ifndef IHM_SOFT_GLOBAL_H

#define IHM_SOFT_GLOBAL_H

#include

#if defined(IHM_SOFT_LIBRARY)

# define IHM_SOFT_SHARED_EXPORT Q_DECL_EXPORT

#else

# define IHM_SOFT_SHARED_EXPORT Q_DECL_IMPORT

#endif

#endif // IHM_SOFT_GLOBAL_H

Qml文件

import QtQuick 2.0

import QtQuick.Controls 1.4

import QtQuick.Window 2.0

ApplicationWindow {

visible: true

width: 500

height: 500

Button {

visible: true

iconSource: "resources/t_on_off.png"

}

}

编辑:对不起,主应用程序的代码是一个不包含lib的测试应用程序。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值