Results 1 to 20 of 25

Thread: QSqlQuery::isValid returns false

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #5
    Join Date
    Feb 2008
    Posts
    154
    Thanks
    12
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QSqlQuery::isValid returns false

    that is the code i use
    Qt Code:
    1. #include "shamelareader.h"
    2.  
    3. shamelaReader::shamelaReader(QWidget *parent)
    4. : QMainWindow(parent)
    5. {
    6. mainText = new QTextEdit(this);
    7. setCentralWidget(mainText);
    8.  
    9. db= QSqlDatabase::addDatabase("QODBC");
    10. db.setDatabaseName("DRIVER={Microsoft Access Driver (*.mdb)};FIL={MS Access};DBQ=c:\\book.mdb");
    11. db.open();
    12.  
    13.  
    14. createActions();
    15. createToolBar();
    16.  
    17. query = new QSqlQuery();
    18. query->exec("SELECT name FROM employee");
    19. query->next();
    20. mainText->setText(query->value(0).toString());
    21.  
    22. }
    23. void shamelaReader::createActions()
    24. {
    25. nextAct = new QAction(tr("&Next"),this);
    26. connect(nextAct, SIGNAL(triggered()), this, SLOT(next()));
    27.  
    28. prevAct = new QAction(tr("&previous"),this);
    29. connect(prevAct, SIGNAL(triggered()), this, SLOT(prev()));
    30.  
    31. firstAct = new QAction(tr("first"), this);
    32. connect(firstAct, SIGNAL(triggered()), this, SLOT(first()));
    33.  
    34. lastAct = new QAction(tr("last"), this);
    35. connect(lastAct, SIGNAL(triggered()), this, SLOT(last()));
    36.  
    37.  
    38. }
    39.  
    40. void shamelaReader::createToolBar()
    41. {
    42. toolBar = addToolBar(tr("Navigation"));
    43. toolBar->addAction(firstAct);
    44. toolBar->addAction(nextAct);
    45. toolBar->addAction(prevAct);
    46. toolBar->addAction(lastAct);
    47. }
    48.  
    49. void shamelaReader::next()
    50. {
    51. query->next();
    52. mainText->setText(query->value(0).toString());
    53. }
    54.  
    55. void shamelaReader::prev()
    56. {
    57. query->previous();
    58. mainText->setText(query->value(0).toString());
    59. }
    60.  
    61. void shamelaReader::first()
    62. {
    63. query->first();
    64. mainText->setText(query->value(0).toString());
    65. }
    66.  
    67. void shamelaReader::last()
    68. {
    69.  
    70. query->last();
    71. if(query->isActive())
    72. QMessageBox::warning(this, "title", "Active true");
    73.  
    74. if(query->isValid())
    75. QMessageBox::warning(this, "title", "true");
    76.  
    77. mainText->setText(query->value(0).toString());
    78. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by wysota; 13th March 2008 at 15:15. Reason: Changed [qtclass] to [code]

Similar Threads

  1. Replies: 4
    Last Post: 8th July 2007, 14:26
  2. connect returns false
    By krivenok in forum Qt Programming
    Replies: 6
    Last Post: 21st February 2006, 20:01

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
  •  
Qt is a trademark of The Qt Company.