Advertisement
korwru

Failure QT App (qsqlite plugin)

Apr 5th, 2013
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //NOT WORKING PROGRAM
  2.  
  3. //////////////////////////////////////////////////////////////
  4. //FILE cdatabase.h
  5. //////////////////////////////////////////////////////////////
  6. #ifndef CDATABASE_H
  7. #define CDATABASE_H
  8.  
  9. #include <QtSql/QSqlDatabase>
  10. #include <QtSql/QSqlError>
  11. #include <QString>
  12.  
  13. class CDatabase
  14. {
  15. public:
  16.     CDatabase();
  17. private:
  18.     void checkDataBase();
  19.     QSqlDatabase db;
  20. };
  21.  
  22. #endif // CDATABASE_H
  23.  
  24.  
  25.  
  26. //////////////////////////////////////////////////////////////
  27. //FILE cdatabase.cpp
  28. //////////////////////////////////////////////////////////////
  29. #include "cdatabase.h"
  30.  
  31. CDatabase::CDatabase()
  32. {
  33.     QString connection = QString(QSqlDatabase::defaultConnection);
  34.     if (QSqlDatabase::contains(connection)) {
  35.         db = QSqlDatabase::database(connection);
  36.     } else {
  37.         db = QSqlDatabase::addDatabase("QSQLITE", connection);
  38.         db.setDatabaseName("db.sqlite");
  39.         db.open();
  40.     }
  41. }
  42.  
  43. //////////////////////////////////////////////////////////////
  44. //FILE main.cpp
  45. //////////////////////////////////////////////////////////////
  46. #include "mainwindow.h"
  47. #include <QApplication>
  48.  
  49. int main(int argc, char *argv[])
  50. {
  51.     QApplication a(argc, argv);
  52.     MainWindow w;
  53.     w.show();
  54.    
  55.     return a.exec();
  56. }
  57.  
  58. //////////////////////////////////////////////////////////////
  59. //FILE mainwindow.h
  60. //////////////////////////////////////////////////////////////
  61. #ifndef MAINWINDOW_H
  62. #define MAINWINDOW_H
  63.  
  64. #include <QMainWindow>
  65.  
  66. namespace Ui {
  67. class MainWindow;
  68. }
  69.  
  70. class MainWindow : public QMainWindow
  71. {
  72.     Q_OBJECT
  73.    
  74. public:
  75.     explicit MainWindow(QWidget *parent = 0);
  76.     ~MainWindow();
  77.    
  78. private:
  79.     Ui::MainWindow *ui;
  80. };
  81.  
  82. #endif // MAINWINDOW_H
  83.  
  84.  
  85. //////////////////////////////////////////////////////////////
  86. //FILE mainwindow.cpp
  87. //////////////////////////////////////////////////////////////
  88. #include "mainwindow.h"
  89. #include "ui_mainwindow.h"
  90. #include "cdatabase.h"
  91.  
  92. CDatabase db;
  93.  
  94. MainWindow::MainWindow(QWidget *parent) :
  95.     QMainWindow(parent),
  96.     ui(new Ui::MainWindow)
  97. {
  98.     ui->setupUi(this);
  99.  
  100. }
  101.  
  102. MainWindow::~MainWindow()
  103. {
  104.     delete ui;
  105. }
  106.  
  107. //////////////////////////////////////////////////////////////
  108. //FILE mainwindow.ui
  109. //////////////////////////////////////////////////////////////
  110. <ui version="4.0">
  111.  <class>MainWindow</class>
  112.  <widget class="QMainWindow" name="MainWindow" >
  113.   <property name="geometry" >
  114.    <rect>
  115.     <x>0</x>
  116.     <y>0</y>
  117.     <width>400</width>
  118.     <height>300</height>
  119.    </rect>
  120.   </property>
  121.   <property name="windowTitle" >
  122.    <string>MainWindow</string>
  123.   </property>
  124.   <widget class="QMenuBar" name="menuBar" />
  125.   <widget class="QToolBar" name="mainToolBar" />
  126.   <widget class="QWidget" name="centralWidget" />
  127.   <widget class="QStatusBar" name="statusBar" />
  128.  </widget>
  129.  <layoutDefault spacing="6" margin="11" />
  130.  <pixmapfunction></pixmapfunction>
  131.  <resources/>
  132.  <connections/>
  133. </ui>
  134.  
  135.  
  136. //////////////////////////////////////////////////////////////
  137. //FILE wolqru.pro
  138. //////////////////////////////////////////////////////////////
  139. QT       += core gui sql
  140.  
  141. greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
  142.  
  143. TARGET = wolqru
  144. TEMPLATE = app
  145.  
  146.  
  147. SOURCES += main.cpp\
  148.         mainwindow.cpp \
  149.     cdatabase.cpp
  150.  
  151. HEADERS  += mainwindow.h \
  152.     cdatabase.h
  153.  
  154. FORMS    += mainwindow.ui
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement