[英]Invisible UI in an QAction Signal Slot
Good morning 早上好
I am programming a very simple for also very specific task using Qdesigner and C++ 17 under ubuntu. 我在ubuntu下使用Qdesigner和C ++ 17编写一个非常简单的非常特殊的任务。 The aims of my GUI and my issue are detail as follow.
我的GUI和我的问题的目标详述如下。
AIMS: 目的:
I need to labelized a several dataset of images. 我需要标记几个图像数据集。 For Input an algorithm gave me three output that are stored in four folders, then I will diplay each image from the input dataset side to side with each one of the three corresponding output data and finaly take a boolean decision concerning the quality of the result of the algorithm.
对于输入,算法给了我三个输出,存储在四个文件夹中,然后我将每个图像从输入数据集一侧显示到三个相应的输出数据中的每一个,并最终采取布尔决定关于结果的质量。算法。 Because I applied this algorithm on several dataset I want to select for each one the input and the three output folder when I start my project.
因为我在几个数据集上应用了这个算法,所以当我启动项目时,我想为每个数据集选择输入和三个输出文件夹。
ISSUE: 问题:
I made the main window inside I load each image and took the decision. 我在内部制作主窗口,我加载每个图像并做出决定。 I evaluate it in a constraint case it work well.
我在一个约束的情况下评估它运作良好。 I order to achieve my goal for the opening project I made a second UI where I what the open projet use to looklike.
为了实现我的开放项目的目标,我制作了第二个UI,其中我使用了开放式项目。 I evaluate that second UI in a context outside the main window it work well either.
我在主窗口之外的上下文中评估第二个UI,它也可以正常工作。 So I call this ui in the slot method but there when I call the menu nothing happen.
所以我在插槽方法中调用这个ui,但是当我调用菜单时没有任何事情发生。 Thanks to a
std::cout
instance I can check the slot method is called when I click on the menu or use the shortcut however nothing happen. 感谢
std::cout
实例,我可以检查当我单击菜单或使用快捷方式时调用插槽方法,但没有任何反应。
Here is the slot method that is called by the QMenu
object. 这是
QMenu
对象调用的slot方法。
void main_gui::on_New_Project_triggered()
{
std::cout<<"NEW PROJECT "<<std::endl;
new_project3 np(this,this);
// new_project3 np(this,this->parent());
np.show();
np.raise();
np.activateWindow();
}
The signature of the new_project3 class constructor is that : new_project3类构造函数的签名是:
new_project3(main_gui* main_window, QWidget *parent);
For the first argument I share the main_gui
instance with the new_project3
class in order to initialize the several QStringList
without copy. 对于第一个参数,我与
new_project3
类共享main_gui
实例,以便初始化几个没有副本的QStringList
。
Thanks in advance for any help. 在此先感谢您的帮助。
EDIT 编辑
SOLUTION: 解:
The class new_project3
inherited from the class QWidget
. 类
new_project3
继承自类QWidget
。 For some reason I don't know I didn't arrive to make any instance of new_project3
working inside the class inherited from QMainWindows
. 出于某种原因,我不知道我没有到达使得在从
QMainWindows
继承的类中工作的new_project3
任何实例。 However I modified the inheritance of new_project3
in order to inherit from the class QDialog
and then the following code work just fine : 但是我修改了
new_project3
的继承以便从类QDialog
继承,然后下面的代码工作得很好:
void main_gui::on_New_Project_triggered()
{
std::cout<<"NEW PROJECT "<<std::endl;
new_project3 np(this,this);
np.exec();
}
That have fix my issue. 这解决了我的问题。 I wonder to know what is written in
exec()
that fix my issue. 我想知道在
exec()
中写的是什么来解决我的问题。 But that's will for another question. 但这是另一个问题的意思。
.exec()
(member of QDialog
but not of QWidget
) execute an event loop and make it modal (synchronous, blocker). .exec()
( QDialog
成员但不是QWidget
成员)执行一个事件循环并使其成为模态(同步,阻塞)。 In your original code the widget was a local object, destroyed as far as the slot ended. 在您的原始代码中,小部件是一个本地对象,在插槽结束时被销毁。 As
.show()
is non-blocking, the widget was marked displayed and destroyed almost immediately. 由于
.show()
是非阻塞的,因此窗口小部件几乎立即被标记显示和销毁。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.