必须在 QWidget 之前构造 QApplication [英] Must construct a QApplication before a QWidget

查看:50
本文介绍了必须在 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆