Import string from another window (newDialog.ui) to MainWindow?

  • Hi, I've made a settings window (a new GUI class). When I click on a button named "Settings" in my MainWindow, the settings window opens. Everything ok. But in this settings window you can choose a working directory from a QFileDialog.. The returned QString should be imported into my MainWindow class.. A little pictorialization:

    How can I solve this? I thought of QSettings, but I never used this before and the example in the doc is complicated.

  • No one can help? It's urgent..

  • Hi
    You could provide a method in NewDialog to return the string

  • You also can emit a signal with a string and connect inside your MainWindow class.

  • Since settings are often needed from all classed across the program, you could store the information in a "global" class, e.g. named properties and make them available via static.

  • What I understand from your requirement is that your settings window is child of your Mainwindow.
    So, you should have definitely passed MainWindow as parent in your Settings window constructor.
    If that is the case, then you can write a public member fucntion say SetFileName() and you can call it in your settings windows after returning from QFileDialog::getExistingDirectory().

    Its something like this

    if (!dir.isEmpty()

    Passing parent widget to the child's constructor is the proper way to do it. Even though you didn't do it you can use QWidget::parentWidget() to get its immediate parent. But you should make sure that it exists.

Log in to reply