View Full Version : Updating a QTableWidget through a Dialog
dragon
14th January 2006, 09:19
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
void ContactWindow::edit(QTableWidgetItem *item )
{
if(item != contactTable->currentItem())
return;
if(item)
{
contactDialog dlg(this);
if(dlg.exec() == QDialog::Accepted)
dlg.leBedrijf->setText(item->text());
}
}
vitaly
14th January 2006, 10:48
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:
ContactDialog dlg(this);
dlg.setSomeField(item->text());
if (dlg.exec() == QDialog::Accepted) {
// Do something
}
dragon
14th January 2006, 11:29
Thanks vitaly for your answer.
The problem is solved.
GreyGeek
19th January 2006, 21:16
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:
#ifndef DLGLOGIN_H
#define DLGLOGIN_H
#include "ui_dlglogin.h"
class dlgLogin : public QDialog
{
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:
//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[] ) {
QString strRejected = "";
QApplication app(argc, argv);
app.setQuitOnLastWindowClosed(false);
dlgLogin dlg;
if( dlg.exec() == QDialog::Accepted ){
QSqlDatabase hapdb = QSqlDatabase::addDatabase(DBDRIVER);
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,
QMessageBox::Ok,QMessageBox::NoButton,QMessageBox: :NoButton);
return 1;
}
} else {
strRejected = QString("User Canceled the login!").toLatin1();
QMessageBox::information(0,"Login Rejected!",strRejected,
QMessageBox::Ok,QMessageBox::NoButton,QMessageBox: :NoButton);
return 2;
}
}
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.