Must construct a QApplication before a QWidget(必须在 QWidget 之前构造 QApplication)
问题描述
到处都只是在 QPaintDevice 之前"的问题,而且我的错误无处不在.所以,我们开始吧.
Everywhere only just "before QPaintDevice" questions and nowhere is my error. So, here we go.
我需要一个 extern QWidget 才能从外部访问它(因为我不知道有任何其他方法可以做到这一点).基本上,我需要这个:从 1 个窗口创建 2 个 QWidget,转到第一个窗口,然后从那里隐藏主窗口并显示由主窗口创建的第二个窗口(虽然主窗口不是 main(),但它也是 QWidget).
I need an extern QWidget to be able to get access to it from outside (because I don't know any other ways to do it). Basically, I need this: Create 2 QWidgets from 1 window, go to first window and from there hide main window and show second window created by main window (although main window is not main(), it is QWidget too).
我加了
extern QWidget *widget = new QWidget
以可能的方式无处不在,但我仍然收到此消息.我想,这意味着我需要创建我的 QApplication(在 main.cpp 中),然后才声明任何 QWidget.但是我怎样才能从另一个 QWidgets 访问那些 QWidgets?
everywhere and everyhow in possible ways, and I still got this message. I suppose, it means that I need to create my QApplication (in main.cpp) and only then declare any QWidgets. But then HOW can I access those QWidgets from another QWidgets?
代码在这里:https://github.com/ewancoder/game/tree/QWidget_before_QApp_problem
附:最终目标是能够在 Battle.cpp 中显示和隐藏 gamewindow.cpp 和 world.cpp(只是普通类)
P.S. The final goal is to be able show and hide both gamewindow.cpp and world.cpp from battle.cpp (just regular class)
顺便说一句,添加 Q_OBJECT 和 #include 都不起作用.
And btw, adding Q_OBJECT and #include both don't work.
无论如何,如果我不能从一个窗口到另一个窗口使用函数,那又有什么意义呢?我可以在另一个窗口中有一个窗口,然后在那个窗口中有另一个窗口,然后在另一个窗口中有一个窗口……但是从最后一个到上一个,我什么都做不了.在 Delphi 工作多年后,这对我来说似乎很奇怪.
Anyway, if I cannot use functions from one window to another, than what's the point? I can have one window in another, and then another in that one, and then one in that another... but I can't do anything from the last to the previous. After years on Delphi that seems strange to me.
推荐答案
可能对前作者没有帮助,但其他人面临问题.我只是将调试库误认为是发行版而得到了这个错误.因此,请检查您的链接器设置,如果您确定实现正确(首先实例化应用程序,然后使用小部件).
Maybe not helping the former author, but others facing the problem. I simply got this error by mistaking a debug-library with a release one. So check your linker settings, if you are sure the implementation is done right (first instancing application and then using widgets).
这篇关于必须在 QWidget 之前构造 QApplication的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:必须在 QWidget 之前构造 QApplication


基础教程推荐
- 如何使图像调整大小以在 Qt 中缩放? 2021-01-01
- 为什么语句不能出现在命名空间范围内? 2021-01-01
- 管理共享内存应该分配多少内存?(助推) 2022-12-07
- 从 std::cin 读取密码 2021-01-01
- 为 C/C++ 中的项目的 makefile 生成依赖项 2022-01-01
- 如何在不破坏 vtbl 的情况下做相当于 memset(this, ...) 的操作? 2022-01-01
- Windows Media Foundation 录制音频 2021-01-01
- 如何“在 Finder 中显示"或“在资源管理器中显 2021-01-01
- 在 C++ 中循环遍历所有 Lua 全局变量 2021-01-01
- 使用从字符串中提取的参数调用函数 2022-01-01