How to get acess to a value from another dialog in mainwindow
-
I have two QMainWindow in my app (ProcessList and MainWindow). ProcessList lists all running processes in my os in a QTableWidget. I wanted to select the PID in the QTableWidget and finally present it in my MainWindowApp dialog. How can I do that?
I have defined a signal in my processlist.h file like the following one:
signals: void pidAvailable(const int&);
Then I defined the following method which a cell (PID cell) selected, it emits PID number like the following:
void ProcessList::on_tableWidget_cellClicked(int row, int column) { int pid = ui->tableWidget->item(row, column)->text().toInt(); emit pidAvailable(pid); }
Then, I have defined the following slot in my MainWindow:
public slots: void pidHandler(const int& arg_pid);
Its implementation:
void MainWindow::pidHandler(const int &arg_pid) { ui->lineEditProcessID->setText(QString::number(arg_pid)); }
Also, I don't know how should I connect these two things together in my application. However, How should I do now?
-
I have two QMainWindow in my app (ProcessList and MainWindow). ProcessList lists all running processes in my os in a QTableWidget. I wanted to select the PID in the QTableWidget and finally present it in my MainWindowApp dialog. How can I do that?
I have defined a signal in my processlist.h file like the following one:
signals: void pidAvailable(const int&);
Then I defined the following method which a cell (PID cell) selected, it emits PID number like the following:
void ProcessList::on_tableWidget_cellClicked(int row, int column) { int pid = ui->tableWidget->item(row, column)->text().toInt(); emit pidAvailable(pid); }
Then, I have defined the following slot in my MainWindow:
public slots: void pidHandler(const int& arg_pid);
Its implementation:
void MainWindow::pidHandler(const int &arg_pid) { ui->lineEditProcessID->setText(QString::number(arg_pid)); }
Also, I don't know how should I connect these two things together in my application. However, How should I do now?
What about
connect(processList, &ProcessList::pidAvailable, this, &MainWindow::pidHandler);
?
You need to have access to a pointer to
ProcessList
inMainWindow
-
You need a pointer named
processList
(or how you want to name it) in your MainWindow class.At least one class needs to know about the other, otherwise you can not connect them.
Store a pointer to
ProcessList
window inMainWindow
for example.
(IncludeprocessList.h
and create member variable which holds pointer toprocessList
)Easiest way would be to create your
processList
inside MainWindow. -
You need a pointer named
processList
(or how you want to name it) in your MainWindow class.At least one class needs to know about the other, otherwise you can not connect them.
Store a pointer to
ProcessList
window inMainWindow
for example.
(IncludeprocessList.h
and create member variable which holds pointer toprocessList
)Easiest way would be to create your
processList
inside MainWindow. -
@Pl45m4 It compiled and run but I can't get the value emited and present it in my lineedit.
Debug and check what value your
int
has (assuming your connection is correct now) when emitting the signal.
You can pass int by value. You don't need to pass a reference.