Page 1 of 3 123 LastLast
Results 1 to 20 of 57

Thread: Record update windowd entered data saving

  1. #1
    Join Date
    Jan 2006
    Location
    Ljubljana
    Posts
    687
    Thanks
    111
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Update window problem [DESPERATE - NOT SOLVED]

    I have an QSqlTabelModel filled with data from three sql tables. When I press in customer browser button "Insert record" or "Change record", mthe update record window show, which contain several QLineEdit widgets. How do I save entered data into database? My exact question is, how to convert every QLineEdit.text() into corespoding record field and then save it?

    Qt Code:
    1. const int INSERT_RECORD_AT_END=-1;
    2.  
    3. QSqlRecord cDataRecord;
    4.  
    5. cDataRecord.setValue("SIFRA", m_pUpdateWindow->GetCustomerID()->text());
    6. cDataRecord.setValue("DS", m_pUpdateWindow->GetTaxNumber()->text());
    7. cDataRecord.setValue("PRIIMEK", m_pUpdateWindow->GetSurname()->text());
    8. cDataRecord.setValue("IME", m_pUpdateWindow->GetName()->text());
    9. //cDataRecord.setValue("ULICA", m_pUpdateWindow->GetStreetID()->text());
    10. cDataRecord.setValue("STEVILKA_ULICE", m_pUpdateWindow->GetStreetNumber()->text());
    11. cDataRecord.setValue("POSTA_STEVILKA", m_pUpdateWindow->GetZipCode()->text());
    12.  
    13. if(m_pTableModel->insertRecord(INSERT_RECORD_AT_END, cDataRecord))
    14. {
    15. QSqlError error=m_pTableModel->lastError();
    16. if(error.type()!=QSqlError::NoError)
    17. {
    18. qDebug() << m_pTableModel->query().lastQuery();
    19. } // if
    20. } // if
    To copy to clipboard, switch view to plain text mode 
    Is it maybe problem in insertRecord paramaters?
    Last edited by MarkoSan; 9th January 2006 at 19:59.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Record update windowd entered data saving

    Qt Code:
    1. rec.setValue("id", lineedit1->text());
    2. rec.setValue("name", lineedit2->text());
    3. rec.setValue("address", lineedit3->text());
    4.  
    5. //...
    6. model->insertRecord(-1, rec);
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Jan 2006
    Location
    Ljubljana
    Posts
    687
    Thanks
    111
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Record update windowd entered data saving

    Quote Originally Posted by wysota
    Qt Code:
    1. rec.setValue("id", lineedit1->text());
    2. rec.setValue("name", lineedit2->text());
    3. rec.setValue("address", lineedit3->text());
    4.  
    5. //...
    6. model->insertRecord(-1, rec);
    To copy to clipboard, switch view to plain text mode 
    Ok, but how does Qt knows which table write to? Or, if i change the name of field with sql administrator, how to handle that kind of changes?
    Qt 5.3 Opensource & Creator 3.1.2

  4. #4
    Join Date
    Jan 2006
    Location
    Kerala
    Posts
    371
    Thanks
    76
    Thanked 37 Times in 32 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Record update windowd entered data saving

    Well your model knows. Don't they ?
    Your model1 should be some what like this
    Qt Code:
    1. model->setTable("employee");
    To copy to clipboard, switch view to plain text mode 
    We can't solve problems by using the same kind of thinking we used when we created them

  5. The following user says thank you to sunil.thaha for this useful post:

    fnmblot (1st August 2006)

  6. #5
    Join Date
    Jan 2006
    Location
    Ljubljana
    Posts
    687
    Thanks
    111
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Record update windowd entered data saving

    Quote Originally Posted by sunil.thaha
    Well your model knows. Don't they ?
    Your model1 should be some what like this
    Qt Code:
    1. model->setTable("employee");
    To copy to clipboard, switch view to plain text mode 
    Ahaaaam, there is a connection, I see now. Thank you.
    Qt 5.3 Opensource & Creator 3.1.2

  7. The following user says thank you to MarkoSan for this useful post:

    fnmblot (1st August 2006)

  8. #6
    Join Date
    Jan 2006
    Location
    Ljubljana
    Posts
    687
    Thanks
    111
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Record update windowd entered data saving

    Hwo do I then convert data types (QLineEdit.text() returns QString) into SQL data types?
    Qt 5.3 Opensource & Creator 3.1.2

  9. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Record update windowd entered data saving

    What kind of fields? Doesn't providing them as strings work?

  10. #8
    Join Date
    Jan 2006
    Location
    Ljubljana
    Posts
    687
    Thanks
    111
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Record update windowd entered data saving

    Nope, it adds a field, I can see that, but record that wass added is empty. In sql database scheme i have BIGINT(20), VARCHAR(255) and so on. Do I need conversion at all or is there something else wrong? Or, how do I refresh the table?
    Qt 5.3 Opensource & Creator 3.1.2

  11. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Record update windowd entered data saving

    You shouldn't need any conversions. Maybe you should try using the version of setValue with field indexes and not field names.

  12. #10
    Join Date
    Jan 2006
    Location
    Ljubljana
    Posts
    687
    Thanks
    111
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Record update windowd entered data saving

    God damn, I tried both setValue versions, I took a look at sql statement, which executes, all without errors (QSqlError returns NoError). insertRecord statement returns TRUE (which is by the docs OK), but data are still not visible. Any other idea??
    Qt 5.3 Opensource & Creator 3.1.2

  13. #11
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Record update windowd entered data saving

    Are they inserted into the database and not visible in the application or not inserted at all? What happens if you execute the same query "by hand"?

  14. #12
    Join Date
    Jan 2006
    Location
    Ljubljana
    Posts
    687
    Thanks
    111
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Record update windowd entered data saving

    Well, i got the statement:
    Qt Code:
    1. QSqlQuery::lastQuery returned {"SELECT stranka.SIFRA,stranka.DS,stranka.PRIIMEK,stranka.IME,ulica.naziv,stranka.STEVILKA_ULICE,kraj.naziv_kraja FROM stranka,u" size=217}
    To copy to clipboard, switch view to plain text mode 

    from the code:
    Qt Code:
    1. QSqlRecord cDataRecord;
    2.  
    3. cDataRecord.setValue(QString("SIFRA"), m_pUpdateWindow->GetCustomerID()->text());
    4. cDataRecord.setValue(QString("DS"), m_pUpdateWindow->GetTaxNumber()->text());
    5. cDataRecord.setValue(QString("PRIIMEK"), m_pUpdateWindow->GetSurname()->text());
    6. cDataRecord.setValue(QString("IME"), m_pUpdateWindow->GetName()->text());
    7. //cDataRecord.setValue("ULICA", m_pUpdateWindow->GetStreetID()->text());
    8. cDataRecord.setValue(QString("STEVILKA_ULICE"), m_pUpdateWindow->GetStreetNumber()->text());
    9. cDataRecord.setValue(QString("POSTA_STEVILKA"), m_pUpdateWindow->GetZipCode()->text());
    10. if(m_pTableModel->insertRecord(INSERT_RECORD_AT_END, cDataRecord))
    11. {
    12. QSqlError error=m_pTableModel->lastError();
    13. if(error.type()!=QSqlError::NoError)
    14. {
    15. qDebug() << m_pTableModel->query().lastQuery();
    16. } // if
    17. } // if
    To copy to clipboard, switch view to plain text mode 

    There is no INSERT statement at all, what the heck is going on??
    Qt 5.3 Opensource & Creator 3.1.2

  15. #13
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Record update windowd entered data saving

    Try calling submit() or submitAll() on the model.

  16. #14
    Join Date
    Jan 2006
    Location
    Ljubljana
    Posts
    687
    Thanks
    111
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Record update windowd entered data saving

    Same result, empty record added to table, when I reopen the window, this empty record is not shown, so I neither does add empty neither filled record to database. Is maybe problem in QSqlDelegate?
    Last edited by MarkoSan; 6th January 2006 at 08:59.
    Qt 5.3 Opensource & Creator 3.1.2

  17. #15
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Record update windowd entered data saving

    Maybe the problem is with MySQL 5.0?

    Did you try debugging to see if Qt even tries to fill those fields?

  18. #16
    Join Date
    Jan 2006
    Location
    Ljubljana
    Posts
    687
    Thanks
    111
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Record update windowd entered data saving

    As i posted earlier, I think the statement:
    QSqlQuery::lastQuery returned "SELECT stranka.SIFRA,stranka.DS,stranka.PRIIMEK,stranka.I ME,ulica.naziv,stranka.STEVILKA_ULICE,kraj.naziv_k raja FROM stranka,u"size=217
    ,which is created in method insertRecord is not correct.

    Since I am total newbie in SQL, am I right or not?

    It seems, but it is not logical, that method insertRecord does not create an SQL statment, but it should, as I understand the whole thing.

    Or maybe, in the docs there is definition of method:
    Qt Code:
    1. bool QSqlTableModel::insertRecord ( int [I]row[/I], const [URL="http://www.qtcentre.org/forum/qsqlrecord.html"][COLOR=#0000ff][U]QSqlRecord[/U][/COLOR][/URL] & [I]record[/I] )
    To copy to clipboard, switch view to plain text mode 
    The statement in my project is:
    Qt Code:
    1. if(m_pTableModel->insertRecord(INSERT_RECORD_AT_END, cDataRecord))
    To copy to clipboard, switch view to plain text mode 
    cDataRecord is declared as:
    Qt Code:
    1. QSqlRecord cDataRecord;
    To copy to clipboard, switch view to plain text mode 
    As far as I can see, the second parameter is reference to sql record, but i pass like insertRecord(-1, cDataRecord), as seen earlier. Is this ok or not?
    Last edited by MarkoSan; 7th January 2006 at 11:03.
    Qt 5.3 Opensource & Creator 3.1.2

  19. #17
    Join Date
    Jan 2006
    Location
    Ljubljana
    Posts
    687
    Thanks
    111
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Record update windowd entered data saving

    No one has idea????
    Qt 5.3 Opensource & Creator 3.1.2

  20. #18
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Record update windowd entered data saving

    Try this(note the "!"):
    Qt Code:
    1. if( ! m_pTableModel->insertRecord( INSERT_RECORD_AT_END, cDataRecord ) )
    2. {
    3. qDebug() << m_pTableModel->lastError().text();
    4. qDebug() << m_pTableModel->query().lastQuery();
    5. }
    To copy to clipboard, switch view to plain text mode 

  21. #19
    Join Date
    Jan 2006
    Location
    Ljubljana
    Posts
    687
    Thanks
    111
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Record update windowd entered data saving

    Quote Originally Posted by jacek
    Try this(note the "!"):
    Qt Code:
    1. if( ! m_pTableModel->insertRecord( INSERT_RECORD_AT_END, cDataRecord ) )
    2. {
    3. qDebug() << m_pTableModel->lastError().text();
    4. qDebug() << m_pTableModel->query().lastQuery();
    5. }
    To copy to clipboard, switch view to plain text mode 
    I did that, but since operation is sucessfull, qDebug statements are skipped.
    Qt 5.3 Opensource & Creator 3.1.2

  22. #20
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Record update windowd entered data saving

    Quote Originally Posted by MarkoSan
    I did that, but since operation is sucessfull, qDebug statements are skipped.
    How about this?
    Qt Code:
    1. m_pTableModel->insertRecord( INSERT_RECORD_AT_END, cDataRecord );
    2. if( m_pTableModel->submitAll() )
    3. {
    4. qDebug() << "Data submitted successfully";
    5. }
    6. else {
    7. qDebug() << m_pTableModel->lastError().text();
    8. qDebug() << m_pTableModel->query().lastQuery();
    9. }
    To copy to clipboard, switch view to plain text mode 

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.