@Bryan-Kelly said in Open a dialog from other than mainwindow:
@Pl45m4 said in Open a dialog from other than mainwindow:
Is main_x the simplification of your dialog classes dx (d1, d2, d3 or whatever you call them)?
There may be something in the question that I don't understand, but I think: No, its just an integer declared at what I think of as the top level of my application.
Yes, I wasn't asking what main_x is ( I know/can see that), I was rather asking about its meaning in your program / for you.
The topic is named "Open a dialog from other than mainwindow", I made couple suggestions with full examples and code snippets, and now there's an Integer you want to pass somewhere, which I said, works the same as if you would pass any other pointer or data to your dialog.
A term. I am using "main" to indicate the code that is first created when an application is created. If I take the defaults the file names used are mainwindow.h, main.cpp, mainwindow.cpp, and mainwindow.ui. So I have been using "main" to refer to the core of the app. The core that launches and anchors everything else
As said above, it's not about why the variable is called like this. More like what are you trying to do with it and why.
So I was wondering if you just simplified your code for your better understanding... and went from passing a QDialog pointer to passing an int... that's why I was asking.
I will have multiple dialogs that each do some things, and some of the results of those dialogs need to get back to main. I would prefer that the dialogs be able to send such data to main rather than waiting for the user to ask for the data with a button click. Then other dialogs will need that information and should be able to fetch it rather than waiting for the user to click a button in main and send it to various dialogs.
Understood. But the data doesn't "travel" from one dialog to another or to your MainWindow by itself. There needs to be some (user inter-)action going on.
For example, you call the get functions from within the MainWindow.
How it's done and how you pass data to your dialog class, I've already explained in my post here.
And if you don't want the user to click any buttons, what's the point using a QDialog class, which returns a "state" whether the dialog was rejected or accepted by the user?
Ok, so a strategy change. Create a class to serve as a repository for shared data. Call it "repo" for repository. Keep the data private. Provide public get and put functions that dialogs can access. This class will not do any processing, just serve as a repository for shared data.
This sounds like a data "model". Therefore have a look at Qt's Model/View section and classes:
https://doc.qt.io/qt-6/model-view-programming.html
Ask yourself what do you really need/want... How your dialogs (or whatever you are using to display or modify your data) should look like and how you want to manage them.
What kind of data you have?
Consider using a proper data model + the right "view" class for displaying, when you are dealing with more complex data.
So, please, if you don't have any questions regarding how to "Open a dialog from other than mainwindow" left, mark this topic as "solved" and create new topic(s) for your further questions.
Because I feel like this topic isn't going somewhere. You reply to suggestions dealing with your initial problem with new/other issues.