I didn't create the QCoreApplication or QApplication in the class I'm using to manipulate database, but the main.cpp have this declaration like you can see:
------ManipulaDados.h--------
#ifndef MANIPULABANCO_H
#define MANIPULABANCO_H
#include <QSqlError>
#include <QMessageBox>
#include <QSqlDatabase>
#include <QSqlQuery>
class ManipulaBanco{
public:
ManipulaBanco(void);
private:
bool conecta(void);
};
#endif
-----------ManipulaBanco.cpp------------
#include "ManipulaBanco.h"
#include <iostream>
using namespace std;
ManipulaBanco::ManipulaBanco(){
conecta();
}
bool ManipulaBanco::conecta(void){
banco.setHostName("localhost");
banco.setDatabaseName("caixa Xpress");
banco.setUserName("brevleq");
banco.setPassword("hoask8");
if(!banco.open()){
cout<<"Não foi possÃ*vel conectar ao banco!!";
//QMessageBox::critical(0,QObject::tr("Não foi possÃ*vel conectar ao servidor!!"),banco.lastError().text());
return(false);
}
return(true);
}
------------main.cpp-----------
#include <QApplication>
#include "ManipulaBanco.h"
#include "TelaPrincipal.h"
int main(int argc,char *argv[]){
ManipulaBanco aux;
TelaPrincipal *dialog=new(TelaPrincipal);
dialog->show();
return app.exec();
}
------ManipulaDados.h--------
#ifndef MANIPULABANCO_H
#define MANIPULABANCO_H
#include <QSqlError>
#include <QMessageBox>
#include <QSqlDatabase>
#include <QSqlQuery>
class ManipulaBanco{
public:
ManipulaBanco(void);
private:
bool conecta(void);
QSqlDatabase banco;
};
#endif
-----------ManipulaBanco.cpp------------
#include "ManipulaBanco.h"
#include <iostream>
using namespace std;
ManipulaBanco::ManipulaBanco(){
conecta();
}
bool ManipulaBanco::conecta(void){
banco=QSqlDatabase::addDatabase("QPSQL");
banco.setHostName("localhost");
banco.setDatabaseName("caixa Xpress");
banco.setUserName("brevleq");
banco.setPassword("hoask8");
if(!banco.open()){
cout<<"Não foi possÃ*vel conectar ao banco!!";
//QMessageBox::critical(0,QObject::tr("Não foi possÃ*vel conectar ao servidor!!"),banco.lastError().text());
return(false);
}
return(true);
}
------------main.cpp-----------
#include <QApplication>
#include "ManipulaBanco.h"
#include "TelaPrincipal.h"
int main(int argc,char *argv[]){
ManipulaBanco aux;
QApplication app(argc,argv);
TelaPrincipal *dialog=new(TelaPrincipal);
dialog->show();
return app.exec();
}
To copy to clipboard, switch view to plain text mode
These are the principals (the plural is write like this??) source files for this question!!
Bookmarks