waynew
1st November 2009, 23:39
I know I'm doing something wrong here, but I can't see it.
The following application crashes on the line commented when it tries to put the value received from the query into the dialog form.
No crash if I comment that line out.
Can anyone please tell me what I have wrong?
#include "makeStnDB.h"
#include <iostream>
#include <QString>
#include <QtSql>
#include "stninfodialog.h"
#include <QDialog>
#include <QtGui>
#include "ui_stninfodialog.h"
#include <QDebug>
bool makeStnDB() {
QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
db.setDatabaseName("StnInfo.sqlite");
db.open();
QSqlQuery query;
query.exec("CREATE table stnInfo(id int primary key,call varchar(8),name varchar(80), "
"address1 varchar(80),address2 varchar(80),city varchar(80),state varchar(80), "
"postalCode varchar(20),country varchar(40),grid varchar(8), "
"cqZone varchar(8),ituZone varchar(8),latitude varchar(8), "
"longitude varchar(8),licenseClass varchar(12))");
//Check to see if stninfo exists...
query.exec("SELECT call, name, address1, address2, city, state, postalCode, country, grid, cqZone, ituZone, latitude, longitude, licenseClass FROM stnInfo");
StnInfoDialog *StnInfoD = new StnInfoDialog();
Ui_StnInfoDialog *stn = new Ui_StnInfoDialog();
if (!query.next()) {
// show the entry form if record not exists
StnInfoD->exec();
StnInfoD->raise();
// need to insert data on 'ok' click
} else {
// if record exists retrieve the data and display it
QString call = query.value(0).toString();
qDebug() << call; // value ok in console
stn -> call -> setText(call); // CRASHES ON THIS LINE
}
return query.exec();
}
The following application crashes on the line commented when it tries to put the value received from the query into the dialog form.
No crash if I comment that line out.
Can anyone please tell me what I have wrong?
#include "makeStnDB.h"
#include <iostream>
#include <QString>
#include <QtSql>
#include "stninfodialog.h"
#include <QDialog>
#include <QtGui>
#include "ui_stninfodialog.h"
#include <QDebug>
bool makeStnDB() {
QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
db.setDatabaseName("StnInfo.sqlite");
db.open();
QSqlQuery query;
query.exec("CREATE table stnInfo(id int primary key,call varchar(8),name varchar(80), "
"address1 varchar(80),address2 varchar(80),city varchar(80),state varchar(80), "
"postalCode varchar(20),country varchar(40),grid varchar(8), "
"cqZone varchar(8),ituZone varchar(8),latitude varchar(8), "
"longitude varchar(8),licenseClass varchar(12))");
//Check to see if stninfo exists...
query.exec("SELECT call, name, address1, address2, city, state, postalCode, country, grid, cqZone, ituZone, latitude, longitude, licenseClass FROM stnInfo");
StnInfoDialog *StnInfoD = new StnInfoDialog();
Ui_StnInfoDialog *stn = new Ui_StnInfoDialog();
if (!query.next()) {
// show the entry form if record not exists
StnInfoD->exec();
StnInfoD->raise();
// need to insert data on 'ok' click
} else {
// if record exists retrieve the data and display it
QString call = query.value(0).toString();
qDebug() << call; // value ok in console
stn -> call -> setText(call); // CRASHES ON THIS LINE
}
return query.exec();
}