Results 1 to 6 of 6

Thread: QSql Column-Header

  1. #1
    Join Date
    May 2009
    Location
    Austria
    Posts
    21
    Qt products
    Qt4
    Platforms
    Windows

    Question QSql Column-Header

    Hello,

    i have a question...
    i have a qsqlite-database and i add a column in the database.
    how can i get the column-headers from the database?
    the problem is, there are some columns and i want to check if there exists
    a column-headername?

    because i don`t want to have two columns who have the same name...

    hope you can help me...

    reinki

  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: QSql Column-Header

    Could you explain (maybe with an example) what you mean?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    May 2009
    Location
    Austria
    Posts
    21
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QSql Column-Header

    Hello,

    i have a little problem...

    i would like to make a database and add in the database a dynamic column...

    the database have to look like this:

    ID | File | Category | German

    and when i click in my programm "add a new language" it have to look like this:

    ID | File | Category | German | English

    and so on...

    the problem is, the first language is in the database and by the second language it creates only the column and put no data in the column...

    Qt Code:
    1. for(i = m_Texte.TextMap.begin(); i != m_Texte.TextMap.end(); i++)
    2. {
    3. model.setEditStrategy(QSqlTableModel::OnManualSubmit);
    4. model.setTable("Texte");
    5. model.select();
    6.  
    7. QModelIndex insertIndex;
    8.  
    9. row = insertIndex.row() == -1 ? 0 : insertIndex.row();
    10. model.insertRow(row);
    11. QSqlRecord record = model.record(row);
    12.  
    13. // ID, File, Category, Language
    14. record.setValue("ID", i->ID);
    15. record.setValue("File", Datei);
    16. record.setValue("Category", i->Kategorie);
    17. record.setValue(Language, i->MapText[spr1]);
    18.  
    19. model.setRecord(row, record); // Record setzen
    20. model.submitAll(); //
    21. qDebug() << model.lastError();
    22. }
    23. model.select();
    To copy to clipboard, switch view to plain text mode 

    when i click to add the new language, by "model.lastError()" i become an error:

    The record could not be fetched! "constraint failed"...

    does anybody know why i get this error?

    kind regards
    Last edited by wysota; 19th May 2009 at 08:48. Reason: missing [code] tags

  4. #4
    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: QSql Column-Header

    The code you pasted is related to adding rows, not columns... Creating the model all over in the for loop looks like a bad idea as well...

    And here:
    Qt Code:
    1. record.setValue(Language, i->MapText[spr1]);
    To copy to clipboard, switch view to plain text mode 
    What does "Language" point to? Is it an enum?
    Last edited by wysota; 19th May 2009 at 08:53.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    May 2009
    Location
    Austria
    Posts
    21
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QSql Column-Header

    Hello,

    I`m sorry that I`ve made the posting code without [code] tags...
    sorry...

    sorry, Language is not a enum, it`s just a QString where the Language is contains...

    so i`ve made a copy & paste mistake:

    Qt Code:
    1. model.setEditStrategy(QSqlTableModel::OnManualSubmit);
    2. model.setTable("Texte");
    3. model.select();
    4.  
    5. for(i = m_Texte.TextMap.begin(); i != m_Texte.TextMap.end(); i++)
    6. {
    7. QModelIndex insertIndex;
    8. row = insertIndex.row() == -1 ? 0 : insertIndex.row();
    9. model.insertRow(row);
    10. QSqlRecord record = model.record(row);
    11.  
    12. // ID, File, Category, Language
    13. record.setValue("ID", i->ID);
    14. record.setValue("File", Datei);
    15. record.setValue("Category", i->Kategorie);
    16. record.setValue("Language", i->MapText[spr1]);
    17.  
    18. model.setRecord(row, record); // set record
    19. model.submitAll(); //
    20. qDebug() << model.lastError();
    21. }
    22. model.select();
    To copy to clipboard, switch view to plain text mode 

    can anybody help me with my problem?
    Last edited by reinki0013; 19th May 2009 at 09:09.

  6. #6
    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: QSql Column-Header

    What is "insertIndex"? You can't create indexes on your own, you have to ask the model to provide one for you. And still I don't know how the code you pasted is related to the code you described.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Replies: 0
    Last Post: 5th November 2008, 14:31
  2. How to customize horizontal header (diagonal header view)
    By vairamuthu.g in forum Qt Programming
    Replies: 4
    Last Post: 4th September 2008, 15:59
  3. Replies: 0
    Last Post: 10th November 2006, 13:46
  4. hidden QListView column suddenly visible
    By edb in forum Qt Programming
    Replies: 10
    Last Post: 27th January 2006, 08:00

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.