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

查看:439
本文介绍了必须在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中),然后才声明任何QWidgets。但是然后我如何才能从另一个QWidget访问那些QWidget?

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

PS最终目标是能够显示和隐藏gamewindow.cpp和world.cpp从Battle.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天全站免登陆