从本机iOS gui切换到Qt gui
Switching from native iOS gui to Qt gui
我目前有一个本机iOS GUI和一个Qt GUI。我正试着从一个换到另一个。
需要明确的是:当我点击原生GUI上的按钮时,我希望Qt GUI显示出来,反之亦然。
我已经找到了我必须添加哪些库才能使用Qt Stuff。我在AppDelegate.mm
文件中创建了一个QApplication
:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions: (NSDictionary *) launchOptions {
// receive int argc, and char** argv for the QApplication.
_qApp = new QApplication(_argc, _argv);
}
此外,我的Qt应用程序(目前)看起来是这样的:
void createQtGUI() {
QPushButton* btn = new QPushButton("Some Button");
QLabel* lbl = new QLabel("QTGui");
QVBoxLayout* layout = new QVBoxLayout();
layout->addWidget(lbl);
layout->addWidget(btn);
QWidget* window = new QWidget();
window->setLayout(layout);
window->show();
}
在本机iOS GUI中按下按钮时,我正在ViewController.mm
中调用createQtGUI
方法。代码运行时没有抛出任何错误,但是:
Qt GUI不显示。应用程序仍然显示本机gui,而不切换到Qt gui
有人知道怎么解决这个问题吗?
我终于找到了缺失的东西:
Qt对象提供了一个名为winId()
的方法。此方法返回一个WId
,它实际上是(在iOS上)UIView*
。
您必须将UIView*
作为子视图添加到主视图中。
为了实现这一点,我更改了createQtGUI
方法如下:
WId createQtGUI() {
... // nothing changed here (only at the end)
window->show();
return window->winId();
}
在我的ViewController.mm
(我称之为方法)中:
- (IBAction)ButtonClicked:(id)sender {
UIView* newView = (__bridge UIView*)reinterpret_cast<void*>(createQtGUI());
[self.view addSubview:newView];
}
注意:双重强制转换(__bridge UIView*)reinterpret_cast<void*>(...)
是必要的,因为在Objective-C++中不能仅从WId
强制转换为UIView*
。
相关文章:
- 如何防止 std::thread 在 QT 中冻结 GUI?
- Qt GUI使用Qfiledialogbox和qlabel显示视频,这是我的代码
- Qt,操作缓慢时不要冻结GUI输入元素
- 试图打开并读取一个.txt文件,但它从原始文件中删除了实际文本(Qt GUI C++
- 如何防止GUI挂起,同时允许第二次操作与Qt中的第一次操作一起执行
- 带GUI的Qt多线程
- Visual Studio with qt 无法编译 gui 类
- Qt 如何将数据从一个 GUI 传递到另一个线程
- 如何使用Visual Studio 2017和Qt开发GUI应用程序?
- 是否可以在QT GUI应用程序中处理事件时播放加载动画指示器?
- Qt:工作线程和 GUI 事件之间的关系
- GUI在qt中同时更新和控制
- 您将如何在现有的QT Creator GUI项目中实现ROS发布者和订阅者?
- 当我使用 GUI 开发 QT 动态库时,如何查看我的 QT UI?
- 如何使用.UI文件在QT Creator中使用CMAKE制作GUI QT项目
- 如何在没有网络的情况下控制NodeMCU,但使用像Qt这样的GUI(通过wifi)?
- QT Windows GUI-无需qtSingLeaplication即可如何打开一个实例
- GUI QT全局变量错误
- 逻辑(c++)与GUI (Qt)分离的概念及基本问题
- C++ Pointer GUI QT