Results 1 to 7 of 7

Thread: QSqlQuery problem (insert once but create two rows!!!)

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Sep 2011
    Posts
    45
    Thanks
    17
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Default Re: QSqlQuery problem (insert once but create two rows!!!)

    For reason of avoiding creating a new thread. Could that line of code "connect(this, SIGNAL(senddata(const QString &)), server, SIGNAL(getdata(const QString &)));" cause the problem, which was described above?

    here is the code, what I have in the server-class:
    Qt Code:
    1. qDebug() << "name: " + name << "staus: " + status << "pass: " + pass;
    2. bool ok;
    3. {
    4. QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL", "db");
    5. db.setHostName(this->dbAddress);
    6. db.setPort(this->dbPort);
    7. db.setDatabaseName(this->dbName);
    8. db.setUserName(this->AdminName);
    9. db.setPassword(this->AdminPass);
    10. ok = db.open();
    11. if(ok)
    12. {
    13. QSqlQuery query("INSERT INTO people(name, status, pass) VALUES('" + name + "', '"
    14. + status + "', '" + pass + "')", db);
    15. query.exec();
    16. query.clear();
    17. }
    18. db.close();
    19. }
    20. QSqlDatabase::removeDatabase("db");
    To copy to clipboard, switch view to plain text mode 

    Output is:

    "name: user" "staus: user" "pass: 12dea96fec20593566ab75692c9949596833adc9"

    In my humble opinion, if I got only line with names, passes and statuses, it doesn't. But still I've got every time two new lines in the database table... Where can be a problem?

  2. #2
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: QSqlQuery problem (insert once but create two rows!!!)

    If you are afraid that connection has been made multiple times, use Qt::UniqueConnection
    Qt Code:
    1. connect(this, SIGNAL(senddata(const QString &)), server, SIGNAL(getdata(const QString &)),Qt::UniqueConnection);
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Replies: 4
    Last Post: 11th October 2014, 14:21
  2. [pyqt] Can't insert Nulls Using QSqlQuery.execBatch
    By ftnirp in forum Qt Programming
    Replies: 0
    Last Post: 3rd October 2011, 21:07
  3. qsqlquery insert error
    By fantom in forum Qt Programming
    Replies: 4
    Last Post: 23rd February 2011, 17:15
  4. TableView + SqlQueryModel: can't insert or edit rows
    By jiveaxe in forum Qt Programming
    Replies: 3
    Last Post: 27th September 2008, 21:55
  5. Insert rows...
    By steg90 in forum Qt Programming
    Replies: 13
    Last Post: 18th September 2007, 13:36

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.