I hate to ask for help on something this simple, but I'm trying to learn C++ and Qt at the same time - can't find an answer in any of my books or online, so...
I have a dialog (stninfodialog) that works fine when called from a menu pick on the main window.
Now I need to call that dialog from a function in a different class.
Simple in Java, but... I can't see how to do it in Qt/C++.
Here is the relevant code from the main window cpp:
#include <QtGui>
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "makestndb.h"
MainWindow
::MainWindow(QWidget *parent
){
ui->setupUi(this);
setupActions();
statusBar()->addPermanentWidget(mStatLabel);
connect(ui->call, SIGNAL(textChanged()), this, SLOT(updateStats()));
StnInfoD = new StnInfoDialog;
bool chkStnInfo = makeStnDB();
}
void MainWindow::setupActions()
{
connect(ui->actionStn_Info, SIGNAL(triggered(bool)),
this, SLOT(stnInfo()));
}
void MainWindow::stnInfo()
{
StnInfoD->show();
}
#include <QtGui>
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "makestndb.h"
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent), ui(new Ui::MainWindow)
{
ui->setupUi(this);
setupActions();
mStatLabel = new QLabel;
statusBar()->addPermanentWidget(mStatLabel);
connect(ui->call, SIGNAL(textChanged()), this, SLOT(updateStats()));
StnInfoD = new StnInfoDialog;
bool chkStnInfo = makeStnDB();
}
void MainWindow::setupActions()
{
connect(ui->actionStn_Info, SIGNAL(triggered(bool)),
this, SLOT(stnInfo()));
}
void MainWindow::stnInfo()
{
StnInfoD->show();
}
To copy to clipboard, switch view to plain text mode
So, now the other class/function (makestndb.h/makestndb.cpp):
makestndb.h
#ifndef MAKESTNDB_H
#define MAKESTNDB_H
#include "stninfodialog.h"
class makeStnDB {
private:
StnInfoDialog *StnInfoD;
};
bool makeStnDB();
#endif // MAKESTNDB_H
#ifndef MAKESTNDB_H
#define MAKESTNDB_H
#include "stninfodialog.h"
class makeStnDB {
private:
StnInfoDialog *StnInfoD;
};
bool makeStnDB();
#endif // MAKESTNDB_H
To copy to clipboard, switch view to plain text mode
makestndb.cpp
#include "makeStnDB.h"
#include <iostream>
#include <QString>
#include <QtSql>
#include "stninfodialog.h"
bool makeStnDB() {
db.setDatabaseName("StnInfo");
db.open();
//Check to see if stninfo exists...
query.exec("SELECT call FROM stnInfo");
if (query.isNull(1)) {
query.exec("CREATE table stnInfo (id int recNum primary key, call varchar(8), "
"name varchar(80), address1 varchar(80), accress2 varchar(80), "
"city varchar(80), state varchar(80), state varchar(40), postalCode varchar(20), "
"country varchar(40), grid varchar(8), cqZone varchar(8), ituZone varchar(8), "
"latitude varchar(8), longitude varchar(8), licenseClass varchar(12)");
//HOW DO I CALL THE STNINFODIALOG FROM HERE?
}
if (!db.open()) {
return false;
}
return true;
}
#include "makeStnDB.h"
#include <iostream>
#include <QString>
#include <QtSql>
#include "stninfodialog.h"
bool makeStnDB() {
QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
db.setDatabaseName("StnInfo");
db.open();
//Check to see if stninfo exists...
QSqlQuery query = QSqlQuery::QSqlQuery("StnInfo");
query.exec("SELECT call FROM stnInfo");
if (query.isNull(1)) {
query.exec("CREATE table stnInfo (id int recNum primary key, call varchar(8), "
"name varchar(80), address1 varchar(80), accress2 varchar(80), "
"city varchar(80), state varchar(80), state varchar(40), postalCode varchar(20), "
"country varchar(40), grid varchar(8), cqZone varchar(8), ituZone varchar(8), "
"latitude varchar(8), longitude varchar(8), licenseClass varchar(12)");
//HOW DO I CALL THE STNINFODIALOG FROM HERE?
}
if (!db.open()) {
return false;
}
return true;
}
To copy to clipboard, switch view to plain text mode
Thanks for any advice!
Bookmarks