Communication of Application Preferences with Main Window...

  • I have a Main Window where I use a GLWidget as the central widget. I have created a Preferences dialog, similar to that of Qt and I would like to change the status of the GLWidget e.g. Enable/Disable Lighting by using a checkbox. I have tried to work with signals but didn't succeed. Any help would be really appreciated.

    Imagine my structure like this:


    I construct the settings dialog the first time through the MainWindow. How do I have access of that specific checkbox,
    inside the glwidget.cpp? Is there any similar example/tutorial in qt demos?

    1. How do you get to your settings dialog ? It sounds like you create it from within the constructor for MainWindow, from what you have written.

    2. Does the settings dialog have an OK/Cancel button box ? I would use the signal from pushing ( or releasing ) the OK button with a slot which would then retreive the state of the checkbox. Although you can also use signals associated with the checkbox itself if you prefer.

    3. Are you using forms in Qt Creator, or are you coding the main window and settings dialog by hand ?

    4. What exactly do you mean by "tried to work with signals but didn't succeed" ? You won't get far with your project without being able to use signals/slots.

    5. Could you post your code if it isn't too huge ?

  • First of all thank you very much for your time and response! I am not able to send you the full code at this moment. Maybe I can prepare a smaller example when I have some time. Here are the answers to your points:

    1. Yes, the Settings dialog is created inside the MainWindow.cpp. I have added a bool variable, so that it is not created from scratch every time.

    2. I have created the Settings dialog as a QWidget. Should I have used the QDialog instead? In my case I have created the OK/Cancel buttons, but I haven't assigned any signals yet, except from closing the settings window. Here I have one question: What is the prefered method? To assign all settings (e.g. 100 checkboxes) as signals to the OK button, or, get the status of each checkbox whenever it is needed?

    3. I have used Qt Creator to design both the Main Window and the Settings dialog, however I am familiar with coding also e.g. connect(...).

    4. I have tried to make simple examples with signals/slots which worked ok, because they were in the same .cpp file. This is the first time I am trying to connect two different .cpp files so I am a bit confused.

    5. As I said above, I may prepare a small example. However, what I need is not so difficult to solve even now, as I imagine. For example, let's assume a MainWindow which has a menu option e.g. File > Preferences. This option creates the Settings window the first time or just shows the already created. Inside settings I have a checkbox e.g. LightCheckbox. Then I would like to check inside my GLWidget.cpp if LightCheckbox is checked or not. Imagine this is something similar to QT Creator Preferences dialog.

    What do you think? Thanx again!

  • I would have a preferences dialog as File>Preferences or Edit>Preferences. I would have a slot for the accepted signal from the OK/Cancel button box, which processes the results from whatever widgets were in the dialog.

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.