Solved Connect closing dialog with a Qt List Widget
-
HI. So my problem is the next: I have a main window with a button that opens a dialog box. Inside that dialog box I create a QStringList and all i want is to return this list from dialog to a QListWidget in main widget when I close the dialog. I suppose it can be solved with signals but i dont know how to use it.
This is how I open the dialog from main widget:
void home::on_AddPeopleBut_clicked() { addpeople* window=new addpeople(this); window->show(); }
In dialog i have the next function :
QStringList addpeople::getList() { return selectedList; }
-
@Dy3zz said in Connect closing dialog with a Qt List Widget:
addpeople* window=new addpeople(this);
You create a dialog each time -> memory leak !
for the signals, just look at the doc:
Signals void accepted() void finished(int result) void rejected()
and there are complete examples:
A modal dialog: void EditorWindow::countWords() { WordCountDialog dialog(this); dialog.setWordCount(document().wordCount()); dialog.exec(); } A modeless dialog: void EditorWindow::find() { if (!findDialog) { findDialog = new FindDialog(this); connect(findDialog, SIGNAL(findNext()), this, SLOT(findNext())); } findDialog->show(); findDialog->raise(); findDialog->activateWindow(); }
-
@Dy3zz said in Connect closing dialog with a Qt List Widget:
addpeople* window=new addpeople(this);
You create a dialog each time -> memory leak !
for the signals, just look at the doc:
Signals void accepted() void finished(int result) void rejected()
and there are complete examples:
A modal dialog: void EditorWindow::countWords() { WordCountDialog dialog(this); dialog.setWordCount(document().wordCount()); dialog.exec(); } A modeless dialog: void EditorWindow::find() { if (!findDialog) { findDialog = new FindDialog(this); connect(findDialog, SIGNAL(findNext()), this, SLOT(findNext())); } findDialog->show(); findDialog->raise(); findDialog->activateWindow(); }
-
@mpergand It worked for me. I did this:
void home::on_AddPeopleBut_clicked() { addpeople dialog(this); dialog.exec(); QStringList a; a=dialog.getList(); qDebug() << a[0]; }
I printed the first element to test . it worked perfectly. Thanks!!