The conexion.cpp modified so the QDataTable tabla on the mainwindow Form uses the cursor created on the conexion.cpp is the next code:
#include <qsqldatabase.h>
#include <qmessagebox.h>
#include <qdatatable.h>
#include <qsqlcursor.h>
#include "conexion.h"
#include "form.h"
bool creaConexion()
{
defaultDB->setDatabaseName( DB_NOM );
defaultDB->setUserName( DB_USR );
defaultDB->setPassword( DB_PASS );
defaultDB->setHostName( DB_HOSTNAME );
if ( ! defaultDB->open() ) {
QMessageBox::warning(0,
"Fallo de conexión",
"No se pudo conectar con la base de datos: " + DB_NOM
+ "tabla: " + DB_TABLA
+ "\n" + defaultDB
->lastError
().
driverText());
return FALSE;
}
QMessageBox::information(0,
"Conexión estabecida",
"Conectado a: " + DB_HOSTNAME
+ " " + "tabla: " + DB_TABLA
+ " "+ DB_NOM
);
return TRUE;
}
bool cierraConexion()
{
if (defaultDB->open()){
defaultDB->close();
QMessageBox::information(0,
"Cerrando conexión",
"Desconectando: " + DB_HOSTNAME
+ " " + DB_NOM
);
return TRUE;
}
else{
return FALSE;
}
}
void llena()
{
qWarning("Inicio del poblado....");
QSqlCursor cursor( DB_TABLA ); // Especifica la tabla
qWarning("Cursor creado apuntando a la tabla" + DB_TABLA);
cursor.select(); // Devuelve todos los registros de la tabla
qWarning("Cursor llenado ");
while ( cursor.next() ) {}
Form().tabla( &cursor );
}
#include <qsqldatabase.h>
#include <qmessagebox.h>
#include <qdatatable.h>
#include <qsqlcursor.h>
#include "conexion.h"
#include "form.h"
QSqlDatabase *defaultDB;
bool creaConexion()
{
defaultDB = QSqlDatabase::addDatabase( DBDRIVER );
defaultDB->setDatabaseName( DB_NOM );
defaultDB->setUserName( DB_USR );
defaultDB->setPassword( DB_PASS );
defaultDB->setHostName( DB_HOSTNAME );
if ( ! defaultDB->open() ) {
QMessageBox::warning(0, "Fallo de conexión", "No se pudo conectar con la base de datos: " + DB_NOM + "tabla: " + DB_TABLA + "\n" + defaultDB->lastError().driverText());
return FALSE;
}
QMessageBox::information(0,"Conexión estabecida","Conectado a: " + DB_HOSTNAME + " " + "tabla: " + DB_TABLA + " "+ DB_NOM);
return TRUE;
}
bool cierraConexion()
{
if (defaultDB->open()){
defaultDB->close();
QMessageBox::information(0,"Cerrando conexión","Desconectando: " + DB_HOSTNAME + " " + DB_NOM);
return TRUE;
}
else{
return FALSE;
}
}
void llena()
{
qWarning("Inicio del poblado....");
QSqlCursor cursor( DB_TABLA ); // Especifica la tabla
qWarning("Cursor creado apuntando a la tabla" + DB_TABLA);
cursor.select(); // Devuelve todos los registros de la tabla
qWarning("Cursor llenado ");
while ( cursor.next() ) {}
Form().tabla( &cursor );
}
To copy to clipboard, switch view to plain text mode
as you could tell on first view.. the last line won't work because it treats the tabla widget it were a function, but I guess it isn't because the compiler shows an error on that.. 
but on one of th exaples provided by QT 3.1.2 the sqltable to be more specific.. it inicialices the datatable as this:
QDataTable tabla( &cursor ); /* data table uses our cursor */
QDataTable tabla( &cursor ); /* data table uses our cursor */
To copy to clipboard, switch view to plain text mode
So I thought (and I guess theres the error xD), that if the widget was already created I maybe could force it to use my cursor from conexion.cpp on the Form.... and then I could fill the... f*** table... help plz
I'm already out of ideas
Bookmarks