Passing data to a new window class.
-
I have an application that I am trying to pass a value to a new window that I'm trying to show. See below;
MainWindow QModelIndex SelectedSchedule;
I want to pass the current value of SelectedSchedule to OrderEd.
void SchedulePanel::on_OrderEntry_PB_clicked() { order *OrderEd; OrderEd = new order (); OrderEd->show(); } I need to retrieve the row of data selected in the schedule view on the MainWindow. Is there a good way to pass this each time I open this window? Thanks
-
C Christian Ehrlicher moved this topic from Qt Creator and other tools
-
@dencla What exactly is the problem? The piece of code you provided does not really help to understand where you're stuck. Your main window is a C++ class, so it can be used like any other C++ class. Implement an interface there to pass it needed data or get data from it.
-
@dencla said in Passing data to a new window class.:
I want to pass the current value of SelectedSchedule to OrderEd.
Access the model at your
SelectedSchedule
index and use some function to retrieve the data at index the way you want it.
There is no general function in custom models to return row data because as the name suggests, each model is different. So you have to provide your own interface to return data as mentioned by @jsulm -
@Pl45m4 Thank You for your feedback. I am learning QT and would like to be able to do this;
void SchedulePanel::on_OrderEntry_PB_clicked() { order *OrderEd; OrderEd = new order (); OrderEd->show(QModelIndex SelectedSchedule); }
Is That possible?
Thanks -
@dencla said in Passing data to a new window class.:
Is That possible?
Not exactly the way you write it but in general, yes.
Like @jsulm said, you have to write your own interface to interact with yourorder
class.
You have a weird naming, by the way... usually you would write classes with capital first letter and object names/variables with lower case.
Anyway, add a function with your desired signature to yourorder
class, likevoid order::show(QModelIndex index) { // do something with index // then call QWidget's show() function show(); }
void SchedulePanel::on_OrderEntry_PB_clicked() { // get model index from selection model QModelIndex selection = yourView->selectionModel()->selectedIndexes(); // make order a member of SchedulePanel to avoid memory leaking // or make it child of SchedulePanel... depends on what class/type order is... // show it using your function, e.g.: OrderEd->show(selection); }