Results 1 to 5 of 5

Thread: [QT]Push button-no action

  1. #1
    Join Date
    May 2010
    Posts
    5

    Default [QT]Push button-no action

    I can compile my program but when i press push button doesn't happen and i don't know why?
    Qt Code:
    1. #include <QtGui/QApplication>
    2. #include "mainwindow.h"
    3.  
    4. int main(int argc, char *argv[])
    5. {
    6. QApplication a(argc, argv);
    7. MainWindow w;
    8. w.show();
    9. return a.exec();
    10.  
    11. }
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. #ifndef MAINWINDOW_H
    2. #define MAINWINDOW_H
    3.  
    4. #include <QMainWindow>
    5. #include "osm_sqlite.h"
    6.  
    7. namespace Ui {
    8. class MainWindow;
    9. }
    10.  
    11. class Osm_Sqlite;
    12.  
    13. class MainWindow : public QMainWindow {
    14. Q_OBJECT
    15. private:
    16. Osm_Sqlite osmdb;
    17. public:
    18. MainWindow(QWidget *parent = 0);
    19. ~MainWindow();
    20.  
    21. protected:
    22. void changeEvent(QEvent *e);
    23.  
    24. private:
    25. Ui::MainWindow *ui;
    26.  
    27. private slots:
    28. void on_pushButton_clicked();
    29. };
    30.  
    31. #endif // MAINWINDOW_H
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. #include "mainwindow.h"
    2. #include "ui_mainwindow.h"
    3. //#include "osm_sqlite.h"
    4.  
    5. MainWindow::MainWindow(QWidget *parent) :
    6. QMainWindow(parent),
    7. ui(new Ui::MainWindow)
    8. {
    9. ui->setupUi(this);
    10. osmdb=Osm_Sqlite("d:\\db1");
    11. }
    12.  
    13. MainWindow::~MainWindow()
    14. {
    15. delete ui;
    16. }
    17.  
    18. void MainWindow::changeEvent(QEvent *e)
    19. {
    20. QMainWindow::changeEvent(e);
    21. switch (e->type()) {
    22. case QEvent::LanguageChange:
    23. ui->retranslateUi(this);
    24. break;
    25. default:
    26. break;
    27. }
    28. }
    29.  
    30. void MainWindow::on_pushButton_clicked()
    31. {
    32. osmdb.Create_clean_database();
    33. //this->osmdb.Create_clean_database();
    34. }
    To copy to clipboard, switch view to plain text mode 

    my class:

    Qt Code:
    1. #ifndef OSM_SQLITE_H
    2. #define OSM_SQLITE_H
    3. #include <QtSql>
    4. #include <QSqlQuery>
    5. class Osm_Sqlite
    6. {
    7. private:
    8. QSqlDatabase db;//=QSqlDatabase::addDatabase("QSQLITE");
    9. QSqlQuery query;
    10. public:
    11. Osm_Sqlite();
    12. Osm_Sqlite(QString patch_to_db);
    13. ~Osm_Sqlite();
    14.  
    15. bool Create_clean_database();
    16.  
    17. };
    18.  
    19. #endif // OSM_SQLITE_H
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. #include "osm_sqlite.h"
    2.  
    3. //konstruktory
    4. Osm_Sqlite::Osm_Sqlite()
    5. {
    6. }
    7. Osm_Sqlite::Osm_Sqlite(QString patch_to_db)
    8. {
    9. this->db=QSqlDatabase::addDatabase("QSQLITE");
    10. this->db.setDatabaseName(patch_to_db);
    11. bool ok = db.open();
    12. qDebug() << ok;
    13. if (!ok)
    14. {
    15. qDebug() << "Błąd: nie można się połączyć z bazą!";
    16. if(this->db.lastError().isValid())
    17. {
    18. qDebug() << this->db.lastError();
    19. }
    20. }
    21. else
    22. {
    23. qDebug() << "Nawiązano połączenie z bazą danych.";
    24. }
    25.  
    26. this->query=QSqlQuery::QSqlQuery(this->db);
    27. //spowoduje że SQLite nie będzie czekało aż operacje na dysku zostaną wykonane. Po prostu zleci ich wykonanie i będzie dalej kontynuować swoje operacje. Może to znacząco zwiększyć szybkość SQLite.
    28. //query.exec("PRAGMA synchronous=OFF");
    29. db.close();
    30. }
    31. //destruktor
    32. Osm_Sqlite::~Osm_Sqlite()
    33. {
    34. this->db.close();
    35. delete &db;
    36. }
    37.  
    38. // usuwa wszystkie wpiosy z bazy danych i tworzy czystÄ… strukture nowej bazy danych;
    39. bool Osm_Sqlite::Create_clean_database()
    40. {
    41.  
    42. bool ok = db.open();
    43.  
    44. QSqlDatabase::database().transaction();
    45.  
    46. // query.exec("select * from tb11");
    47. //
    48. // while (query.next())
    49. // {
    50. // QString name = query.value(0).toString();
    51. //
    52. // qDebug() << name;
    53. // }
    54.  
    55. //usuniecie tabel
    56. query.exec("drop table Pacjent");
    57. query.exec("drop table Dysk");
    58. query.exec("drop table PlikDicom");
    59.  
    60. query.exec("CREATE TABLE Pacjent(id_p INTEGER PRIMARY KEY,Imie VARCHAR(20),Nazwisko VARCHAR(20),Pesel VARCHAR(11),Plec VARCHAR(1));");
    61. query.exec("CREATE TABLE Dysk(id_d INTEGER PRIMARY KEY,NazwaPlyty VARCHAR(20),DataArch VARCHAR(8),id_p INTEGER;");
    62. query.exec("CREATE TABLE PlikDicom(id_pd INTEGER PRIMARY KEY,NazwaPliku VARCHAR(20),DataUtworzenia VARCHAR(8),SeriesDescript VARCHAR(20),Modality VARCHAR(10));");
    63.  
    64. query.exec("CREATE INDEX name_ind on Pacjent(Nazwisko);");
    65. query.exec("CREATE INDEX pesel_ind on Pacjent(Pesel);");
    66. query.exec("CREATE INDEX dane on Pacjent(Pesel,Nazwisko);");
    67. query.exec("CREATE INDEX nazwaplyty_ind on Dysk(NazwaPlyty);");
    68. query.exec("CREATE INDEX dataarch_ind on Dysk(DataArch);");
    69.  
    70. //spowoduje że SQLite nie będzie czekało aż operacje na dysku zostaną wykonane
    71. //query.exec("PRAGMA synchronous=OFF");
    72. QSqlDatabase::database().commit();
    73. //wyswietla informacje jesli nastapily jakies bledy
    74. if(db.lastError().isValid())
    75. {
    76. qDebug() << db.lastError();
    77. return false;
    78. }
    79. db.close();
    80. return true;
    81. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: [QT]Push button-no action

    Where do you call on_pushButton_clicked()?

    You need to connect a signal to this slot.

  3. #3
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: [QT]Push button-no action

    Maybe he is depending on the connectSlotsByName() call in the setupui() method.

  4. #4
    Join Date
    May 2010
    Posts
    5

    Default Re: [QT]Push button-no action

    Maybe i write wrong. When i run my program nth happend when i clicked on button. When i uncomment in
    Osm_Sqlite::Create_clean_database() :

    section:

    query.exec("select * from tb11");
    while (query.next())
    {
    QString name = query.value(0).toString();
    qDebug() << name;
    }

    i should have sth print but nth happen

  5. #5
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: [QT]Push button-no action

    If you use the database like this:

    Qt Code:
    1. QSqlDatabase::database().transaction();
    To copy to clipboard, switch view to plain text mode 
    You need to set a connection name.

    Otherwise, try:

    Qt Code:
    1. db.transaction();
    To copy to clipboard, switch view to plain text mode 

    And the same with commit();

Similar Threads

  1. Hareware Push Button
    By mickeyk191 in forum Newbie
    Replies: 2
    Last Post: 26th January 2010, 12:41
  2. A very small push button
    By Gnurou in forum Qt Programming
    Replies: 2
    Last Post: 15th November 2009, 03:04
  3. Line edit and push button
    By dela in forum Newbie
    Replies: 1
    Last Post: 10th December 2008, 16:10
  4. shape of push button
    By Seema Rao in forum Qt Programming
    Replies: 23
    Last Post: 2nd April 2008, 01:05
  5. Push Button problem!!
    By Seema Rao in forum Qt Programming
    Replies: 1
    Last Post: 22nd April 2006, 16:31

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.