Dialog_Login.h*******
#include <QDialog>
#include <QtSql>
#include <QSqlDatabase>
class Dialog_Login;
}
class Dialog_Login
: public QDialog{
Q_OBJECT
public:
explicit Dialog_Login
(QWidget *parent
= 0);
~Dialog_Login();
void Rellenar_Usuarios();
}:
#include <QDialog>
#include <QtSql>
#include <QSqlDatabase>
class Dialog_Login;
}
class Dialog_Login : public QDialog
{
Q_OBJECT
public:
explicit Dialog_Login(QWidget *parent = 0);
~Dialog_Login();
void Rellenar_Usuarios();
QSqlQueryModel *Modelo1;
QSqlDatabase db;
}:
To copy to clipboard, switch view to plain text mode
Dialog_Login.cpp*
void Dialog_Login::Rellenar_Usuarios()
{
db.setDatabaseName("*******");
db.setHostName("********");
db.setUserName("*****");
db.setPassword("*****");
db.setPort(5432);
if(db.open())
{
query.exec("SELECT id_usuario FROM Usuario");
ui->tableWidget->setRowCount(1);
ui->tableWidget->setColumnCount(1);
ui
->tableWidget
->setHorizontalHeaderLabels
(QString("Usuarios").
split(";"));
int i=0;
while (query.next()) {
i++;
ui->tableWidget->insertRow(i);
}
}
}
void Dialog_Login::on_pushButton_2_clicked()
{
Rellenar_Usuarios();
}
void Dialog_Login::Rellenar_Usuarios()
{
db = QSqlDatabase::addDatabase("QPSQL");
db.setDatabaseName("*******");
db.setHostName("********");
db.setUserName("*****");
db.setPassword("*****");
db.setPort(5432);
if(db.open())
{
QSqlQuery query;
query.exec("SELECT id_usuario FROM Usuario");
ui->tableWidget->setRowCount(1);
ui->tableWidget->setColumnCount(1);
ui->tableWidget->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding);
ui->tableWidget->setHorizontalHeaderLabels(QString("Usuarios").split(";"));
int i=0;
while (query.next()) {
ui->tableWidget->setItem(i,0,new QTableWidgetItem(query.value(1).toString()));
i++;
ui->tableWidget->insertRow(i);
}
}
}
void Dialog_Login::on_pushButton_2_clicked()
{
Rellenar_Usuarios();
}
To copy to clipboard, switch view to plain text mode
I need to see what is in the "id_usuario" field in the user table on in QTableWidget, only for testing
But when i running it, the QTableWidget doesn't fill! What's wrong?? I'm Sorry my bad English!! Thanks
Bookmarks