C++ Qt 创建者,错误信息

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10017025/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 13:31:00  来源:igfitidea点击:

Qt creator, error message

c++qtuser-interface

提问by Gabriel

I am a little rusty with QT but I've had to use it for projects before.

我对 QT 有点生疏,但我以前不得不将它用于项目。

I was wondering if I could make a pop-up window, a small window with it's height/width disabled so the user can't expand it. It should also lock the screen until they press a button on this window.

我想知道我是否可以制作一个弹出窗口,一个禁用高度/宽度的小窗口,因此用户无法展开它。它还应该锁定屏幕,直到他们按下此窗口上的按钮。

I could do all of this in a separate class, but I was wondering. Are there any built-in QT classes that have a little popup like this that I could just modify? I mean making a class just for an error message seems to me a little wasteful. I'm trying to keep the project small.

我可以在单独的课程中完成所有这些,但我想知道。是否有任何内置的 QT 类有一个像这样的小弹出窗口,我可以修改?我的意思是为一个错误消息创建一个类在我看来有点浪费。我正在努力使项目保持小规模。

But if a class is required to be made in order to accomplish this, that is fine. The only problem is I have no clue how to lock the application windows so that you have to do something one window before you can go back to the main application.

但是,如果需要创建一个类来实现这一点,那很好。唯一的问题是我不知道如何锁定应用程序窗口,以便您必须在一个窗口中执行某些操作才能返回主应用程序。

I'm not asking for someone to type out all this code for me, just give me a link or something. I've looked for it but I couldn't find it. Cheers.

我不是要求某人为我输入所有这些代码,只是给我一个链接或其他东西。我已经找过了,但找不到。干杯。

回答by Soumya Kundu

QMessageBox messageBox;
messageBox.critical(0,"Error","An error has occured !");
messageBox.setFixedSize(500,200);

The above code snippet will provide the required message box.

上面的代码片段将提供所需的消息框。

回答by talnicolas

For a simple error message, I would suggest you look into the QMessageBox(the documentation contains little example that should show you how to easily achieve what you need), which is modal too. Using a QDialog for displaying a simple error message is possible too, but maybe too much for such a simple task.

对于一个简单的错误消息,我建议您查看QMessageBox(文档包含的小示例应该向您展示如何轻松实现您需要的内容),它也是模态的。使用 QDialog 显示简单的错误消息也是可能的,但对于这样一个简单的任务来说可能太多了。

回答by nqe

I believe what you are looking for is something along the lines of QDialog. Dialogs can be modal or nonmodal. Modal dialogue "block" interaction with the calling window until the Dialog window has been handled.

我相信你正在寻找的是QDialog 的东西。对话框可以是模态的或非模态的。模态对话“阻止”与调用窗口的交互,直到对话窗口被处理。

You can either subclass QDialog or check to see if one of the default dialog classes will be enough for what you need.

您可以继承 QDialog 或检查默认对话框类之一是否足以满足您的需要。