Updating a QTableWidget through a Dialog
Hello anyone
I have a question
I want to update a QTableWidget through a Dialog is this possible?
When i click with the mouse on a item in the QTableWidget it popup a Dialog.
When i compile everthing works fine but i don't see any item displaying in my Dialog.
I have tried severall options.
See code
Code:
{
if(item != contactTable->currentItem())
return;
if(item)
{
contactDialog dlg(this);
if(dlg.
exec() == QDialog::Accepted) dlg.leBedrijf->setText(item->text());
}
}
Re: Updating a QTableWidget through a Dialog
Quote:
1: contactDialog dlg(this);
2: if(dlg.exec() == QDialog::Accepted)
3: dlg.leBedrijf->setText(item->text());
You try to set some dialog properties in the string 3 (see quoted text) after the dialog is executed and closed (string 2) because the dialog is modal. Try the following:
Code:
ContactDialog dlg(this);
dlg.setSomeField(item->text());
if (dlg.
exec() == QDialog::Accepted) { // Do something
}
Re: Updating a QTableWidget through a Dialog
Thanks vitaly for your answer.
The problem is solved.
Re: Updating a QTableWidget through a Dialog
Quote:
Originally Posted by dragon
Hello anyone
I have a question
I want to update a QTableWidget through a Dialog is this possible?
When i click with the mouse on a item in the QTableWidget it popup a Dialog.
When i compile everthing works fine but i don't see any item displaying in my Dialog.
I have tried severall options.
See code
In addition to Vitaly's answer, you could also preset values in controls in the class of the dialog:
Code:
#ifndef DLGLOGIN_H
#define DLGLOGIN_H
#include "ui_dlglogin.h"
{
Q_OBJECT
public:
Ui::dlgLoginUi dui;
dlgLogin()
{
// called with 'dlgLogin dlg'. Only ID and password required
dui.setupUi(this);
dui.leUserName->setText("your revid");
dui.leUserPassword->setText("");
dui.leUserName->setFocus();
dui.leUserName->selectAll();
}
};
then retrieve them like this:
Code:
//main.cpp
#include <QApplication>
#include <QSqlDatabase>
#include <QSqlError>
#include <QMessageBox>
#include "homestead.h"
#include "dlglogin.h"
#include "wholenamedlg.h"
#ifdef _WIN32 // on Windows
#define DBDRIVER "QOCI"
#define DBHOST "orc1"
#define DBNAME "orc1"
#else // must be on Linux
#define DBDRIVER "QPSQL"
#define DBHOST "localhost"
#define DBNAME "homestead"
#endif
int main( int argc, char * argv[] ) {
app.setQuitOnLastWindowClosed(false);
dlgLogin dlg;
if( dlg.
exec() == QDialog::Accepted ){ hapdb.setHostName(DBHOST);
hapdb.setDatabaseName(DBNAME);
hapdb.setUserName(dlg.dui.leUserName->text());
hapdb.setPassword(dlg.dui.leUserPassword->text());
if ( hapdb.open() ) {
homestead ht;
ht.RevID = dlg.dui.leUserName->text();
ht.show();
app.setQuitOnLastWindowClosed(true);
return app.exec();
} else {
strRejected
= QString("The Login was rejected because: %1").
arg(hapdb.
lastError().
text()).
toLatin1();
QMessageBox::information(0,
"Login Rejected!",strRejected,
return 1;
}
} else {
strRejected
= QString("User Canceled the login!").
toLatin1();
QMessageBox::information(0,
"Login Rejected!",strRejected,
return 2;
}
}