简体   繁体   中英

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. The aims of my GUI and my issue are detail as follow.

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. I evaluate that second UI in a context outside the main window it work well either. So I call this ui in the slot method but there when I call the menu nothing happen. 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.

Here is the slot method that is called by the QMenu object.

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(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.

Thanks in advance for any help.

EDIT

SOLUTION:

The class new_project3 inherited from the class 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 . However I modified the inheritance of new_project3 in order to inherit from the class QDialog and then the following code work just fine :

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. 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). 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM