Page 3 of 4 FirstFirst 1234 LastLast
Results 41 to 60 of 61

Thread: using an isntance of QSqlDatabase for connection defiinition

  1. #41
    Join Date
    Jun 2016
    Posts
    99
    Thanks
    18
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: using an isntance of QSqlDatabase for connection defiinition

    Quote Originally Posted by anda_skoa View Post
    As far as I can tell your loaded Item is empty.

    I.e. the root level Item in UserEventDialog.qml does not have any content.

    My guess is that you don't want that Item at all and also don't want the Component in that file, but that Component element's main Item to be the top level

    Cheers,
    _
    I got busy and didn’t see this reply, your totally right. Moved out competent in that file, thank you for explaining this.

  2. #42
    Join Date
    Jun 2016
    Posts
    99
    Thanks
    18
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: using an isntance of QSqlDatabase for connection defiinition

    yeah sorry didnt see your earlier post thanks for explaining this...

  3. #43
    Join Date
    Jun 2016
    Posts
    99
    Thanks
    18
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: using an isntance of QSqlDatabase for connection defiinition

    I want to be able to archive my old table rows older than certain number of days, I figured I could copy the data from one database table to another database table, not sure if this is the best way to do it ? could you possible help me get a proper archive setup?


    Qt Code:
    1. void sqliteModel::dbConnect(){
    2.  
    3. if(!m_selectDataBase.isValid()){
    4. qDebug() << "error in opening DB";
    5. m_selectDataBase = QSqlDatabase::addDatabase("QSQLITE", "conn2");
    6. m_selectDataBase.setDatabaseName("/home/amet/userLog.db");
    7. }
    8. else{
    9. qDebug() <<"connected to DB" ;
    10. }
    11. m_selectDataBase.open();
    12. }
    13.  
    14. void sqliteModel::archiveDbConnect(){
    15.  
    16. if(!m_archiveDataBase.isValid()){
    17. qDebug() << "error in opening DB";
    18. m_archiveDataBase = QSqlDatabase::addDatabase("QSQLITE", "conn3");
    19. m_archiveDataBase.setDatabaseName("/home/amet/userLogArchive.db");
    20. }
    21. else{
    22. qDebug() <<"connected to DB" ;
    23. }
    24. m_archiveDataBase.open();
    25. }
    26.  
    27. void sqliteModel::archiveEvent(){
    28. dbConnect();
    29. //---archive db connecion---//
    30. archiveDbConnect();
    31.  
    32. QSqlQuery archiveDataQry("SELECT * FROM userlogevents2", m_selectDataBase);
    33. QSqlQuery deleteDataQry(m_selectDataBase);
    34. if(archiveDataQry.exec()){
    35. qDebug()<<"sql statement exicuted fine";
    36. }
    37. else{
    38. qDebug() << "Errors accured with sql statement";
    39. qDebug() << archiveTableQry.lastError();
    40. }
    41.  
    42. QDate rowDate;
    43. QDate archiveDate = QDate::currentDate().addDays(-3);
    44. qDebug() << "deleteDate: "+archiveDate.toString();
    45.  
    46. while(archiveDataQry.next()){
    47. rowDate = archiveDataQry.value(3).toDate();
    48. qDebug() << "results: "+rowDate.toString();
    49. if(archiveDate < rowDate){
    50. qDebug() << "made inside delete condition: ";
    51. archiveDataQry.prepare("INSERT INTO userlogarchive FROM userlogevents2 WHERE dateTime < ?");
    52. archiveDataQry.addBindValue(archiveDate);
    53. deleteDataQry.prepare("DELETE FROM userlogevents2 WHERE dateTime < ?");
    54. deleteDataQry.addBindValue(archiveDate);
    55. if(archiveDataQry.exec()){
    56. qDebug()<<"archive sql statement exicuted fine";
    57. }
    58. else{
    59. qDebug() << "Errors accured with archive sql statement";
    60. qDebug() << archiveDataQry.lastError();
    61. }
    62. if(deleteDataQry.exec()){
    63. qDebug()<<"delete sql statement exicuted fine";
    64. }
    65. else{
    66. qDebug() << "Errors accured with delete sql statement";
    67. qDebug() << deleteDataQry.lastError();
    68. }
    69. }
    70. }
    71. m_selectDataBase.close();
    72. }
    To copy to clipboard, switch view to plain text mode 

  4. #44
    Join Date
    Dec 2009
    Location
    New Orleans, Louisiana
    Posts
    791
    Thanks
    13
    Thanked 153 Times in 150 Posts
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Re: using an isntance of QSqlDatabase for connection defiinition

    Much easier IMHO to attach your archive database to the main database so that you can insert the records into the archive table by selecting the records you want to select for archiving. A hypothetical example would be:
    Qt Code:
    1. ATTACH DATABASE '/home/amet/userLogArchive.db' as arc;
    2. INSERT INTO arc.userlogarchive select * from main.userlogevents2 where dateTime >= ?;
    3. DELETE FROM main.userlogevents2 where dateTime >= ?;
    To copy to clipboard, switch view to plain text mode 
    I write the best type of code possible, code that I want to write, not code that someone tells me to write!

  5. #45
    Join Date
    Jun 2016
    Posts
    99
    Thanks
    18
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: using an isntance of QSqlDatabase for connection defiinition

    I thought keeping the table in another database would be best in case one corrupts, however I can attach the database together to copy over old rows? what is arc?

  6. #46
    Join Date
    Dec 2009
    Location
    New Orleans, Louisiana
    Posts
    791
    Thanks
    13
    Thanked 153 Times in 150 Posts
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Re: using an isntance of QSqlDatabase for connection defiinition

    Quote Originally Posted by jfinn88 View Post
    I thought keeping the table in another database would be best in case one corrupts, however I can attach the database together to copy over old rows?
    The example I posted above will result in the archived records in a seperate db (userLogArchive.db). You'll want to check for successful execution of each of those statements above and I'd start a transaction before the insert and commit after the delete, etc.
    I write the best type of code possible, code that I want to write, not code that someone tells me to write!

  7. #47
    Join Date
    Jun 2016
    Posts
    99
    Thanks
    18
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: using an isntance of QSqlDatabase for connection defiinition

    I see what your saying... I just get little lost on implementing this concept, let me see what I can figure out with the attach database and the transaction()


    Added after 51 minutes:


    haven't looked into the ATTACH DATABASE yet been playing with using two separate connections little more but still having trouble... If I cant get this way to work I will try the attached database way...

    Qt Code:
    1. void sqliteModel::dbConnect(){
    2.  
    3. if(!m_selectDataBase.isValid()){
    4. qDebug() << "error in opening DB";
    5. m_selectDataBase = QSqlDatabase::addDatabase("QSQLITE", "conn2");
    6. m_selectDataBase.setDatabaseName("/home/amet/userLog.db");
    7. }
    8. else{
    9. qDebug() <<"connected to DB" ;
    10. }
    11. m_selectDataBase.open();
    12. }
    13.  
    14. void sqliteModel::archiveDbConnect(){
    15.  
    16. if(!m_archiveDataBase.isValid()){
    17. qDebug() << "error in opening DB";
    18. m_archiveDataBase = QSqlDatabase::addDatabase("QSQLITE", "conn3");
    19. m_archiveDataBase.setDatabaseName("/home/amet/userLogArchive.db");
    20. }
    21. else{
    22. qDebug() <<"connected to DB" ;
    23. }
    To copy to clipboard, switch view to plain text mode 


    Qt Code:
    1. void sqliteModel::archiveEvent(){
    2. dbConnect();
    3. archiveDbConnect();
    4.  
    5. QSqlQuery archiveDataQry("SELECT * FROM userlogevents7", m_selectDataBase);
    6. QSqlQuery copyDataQry(m_archiveDataBase);
    7.  
    8. int id;
    9. QString userName;
    10. QString eventMessage;
    11. QString dateTime;
    12.  
    13. if(archiveDataQry.exec()){
    14. qDebug()<<"sql statement exicuted fine";
    15. }
    16. else{
    17. qDebug() << "Errors accured with sql statement";
    18. qDebug() << archiveDataQry.lastError();
    19. }
    20.  
    21. QDate rowDate;
    22. QDate archiveDate = QDate::currentDate().addDays(-30);
    23. qDebug() << "archiveDate: "+archiveDate.toString();
    24.  
    25. m_selectDataBase.transaction();
    26. copyDataQry.prepare("INSERT INTO userlogarchive (id, userName, eventMessage, dateTime) FROM userlogevents7 VALUES (:id, :userName, :eventMessage, :dateTime) WHERE dateTime < ?");
    27.  
    28. while(archiveDataQry.next()){
    29. rowDate = archiveDataQry.value(3).toDate();
    30. qDebug() << "results: "+rowDate.toString();
    31. if(archiveDate < rowDate){
    32. qDebug() << "made inside delete condition: ";
    33.  
    34. id = archiveDataQry.record().value(0).toInt();
    35. userName = archiveDataQry.record().value(1).toString();
    36. eventMessage = archiveDataQry.record().value(2).toString();
    37. dateTime = archiveDataQry.record().value(3).toString();
    38. copyDataQry.bindValue(0, id);
    39. copyDataQry.bindValue(1, userName);
    40. copyDataQry.bindValue(2, eventMessage);
    41. copyDataQry.bindValue(3, dateTime);
    42. copyDataQry.addBindValue(archiveDate);
    43. }
    44. }
    45.  
    46. //archiveDataQry.prepare("DELETE FROM userlogevents7 WHERE dateTime < ?");
    47. //archiveDataQry.addBindValue(archiveDate);
    48.  
    49. //if(archiveDataQry.exec()){
    50. // qDebug()<<"archive sql statement exicuted fine";
    51. //}
    52. //else{
    53. // qDebug() << "Errors accured with archive sql statement";
    54. // qDebug() << archiveDataQry.lastError();
    55. //}
    56.  
    57. if(copyDataQry.exec()){
    58. qDebug()<<"copy sql statement exicuted fine";
    59. }
    60. else{
    61. qDebug() << "Errors accured with copy sql statement";
    62. qDebug() << copyDataQry.lastError();
    63. }
    64. m_selectDataBase.commit();
    65. m_selectDataBase.close();
    66. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by jfinn88; 12th September 2016 at 21:34.

  8. #48
    Join Date
    Jun 2016
    Posts
    99
    Thanks
    18
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: using an isntance of QSqlDatabase for connection defiinition

    keep getting "Parameter count mismatch" seems to be with binding values I think...

    Qt Code:
    1. void sqliteModel::dbConnect(){
    2.  
    3. if(!m_selectDataBase.isValid()){
    4. qDebug() << "error in opening DB";
    5. m_selectDataBase = QSqlDatabase::addDatabase("QSQLITE", "conn2");
    6. m_selectDataBase.setDatabaseName("/home/amet/userLog.db");
    7. }
    8. else{
    9. qDebug() <<"connected to DB" ;
    10. }
    11. m_selectDataBase.open();
    12. }
    13.  
    14. void sqliteModel::archiveDbConnect(){
    15.  
    16. if(!m_archiveDataBase.isValid()){
    17. qDebug() << "error in opening DB";
    18. m_archiveDataBase = QSqlDatabase::addDatabase("QSQLITE", "conn4");
    19. m_archiveDataBase.setDatabaseName("/home/amet/userLogArchive.db");
    20. }
    21. else{
    22. qDebug() <<"connected to DB" ;
    23. }
    24. m_archiveDataBase.open();
    25. }
    26. void sqliteModel::archiveEvent(){
    27. dbConnect();
    28. archiveDbConnect();
    29.  
    30. QSqlQuery archiveDataQry("SELECT * FROM userlogevents7", m_selectDataBase);
    31. QSqlQuery copyDataQry(m_archiveDataBase);
    32.  
    33. QString id;
    34. QString userName;
    35. QString eventMessage;
    36. QDate dateTime;
    37.  
    38. if(archiveDataQry.exec()){
    39. qDebug()<<"sql statement exicuted fine";
    40. }
    41. else{
    42. qDebug() << "Errors accured with sql statement";
    43. qDebug() << archiveDataQry.lastError();
    44. }
    45.  
    46. QDate rowDate;
    47. QDate archiveDate = QDate::currentDate().addDays(-30);
    48. qDebug() << "archiveDate: "+archiveDate.toString("yyyy-MM-dd");;
    49.  
    50. m_selectDataBase.transaction();
    51. copyDataQry.prepare("INSERT INTO userlogarchive FROM userlogevents7 WHERE id > 0");
    52.  
    53. while(archiveDataQry.next()){
    54. rowDate = archiveDataQry.value(3).toDate();
    55. qDebug() << "results: "+rowDate.toString("yyyy-MM-dd");
    56. //if(archiveDate < rowDate){
    57. //qDebug() << "made inside delete condition: ";
    58.  
    59. id = archiveDataQry.record().value(0).toString();
    60. qDebug() << "id: "+id;
    61. userName = archiveDataQry.record().value(1).toString();
    62. qDebug() << "user name: "+userName;
    63. eventMessage = archiveDataQry.record().value(2).toString();
    64. qDebug() << "event Message : "+eventMessage;
    65. dateTime = archiveDataQry.record().value(3).toDate();
    66. qDebug() << "date : "+dateTime.toString();
    67. copyDataQry.bindValue(0,id);
    68. copyDataQry.bindValue(1, userName);
    69. copyDataQry.bindValue(2, eventMessage);
    70. copyDataQry.bindValue(3, dateTime);
    71. //copyDataQry.addBindValue(archiveDate);
    72. if(copyDataQry.exec()){
    73. qDebug()<<"copy sql statement exicuted fine";
    74. }
    75. else{
    76. qDebug() << "Errors accured with copy sql statement";
    77. qDebug() << copyDataQry.lastError();
    78. }
    79.  
    80. //archiveDataQry.prepare("DELETE FROM userlogevents7 WHERE dateTime < ?");
    81. //archiveDataQry.addBindValue(archiveDate);
    82.  
    83. //if(archiveDataQry.exec()){
    84. // qDebug()<<"archive sql statement exicuted fine";
    85. //}
    86. //else{
    87. // qDebug() << "Errors accured with archive sql statement";
    88. // qDebug() << archiveDataQry.lastError();
    89. //}
    90.  
    91. //}
    92. }
    93. m_selectDataBase.commit();
    94. m_selectDataBase.close();
    95. }
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. class sqliteModel:public QAbstractListModel
    2. {
    3. Q_OBJECT
    4.  
    5. public:
    6. explicit sqliteModel(QObject *parent = 0);
    7.  
    8. ~sqliteModel();
    9.  
    10. enum userEventRoles {idRole= Qt::UserRole + 220, nameRole, msgRole, dateRole};
    11.  
    12. int rowCount(const QModelIndex & parent) const;
    13.  
    14. QHash<int, QByteArray> roleNames() const;
    15.  
    16. QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const;
    17.  
    18. Q_INVOKABLE void addEvent(const userEventLogMsg &msg);
    19.  
    20. Q_INVOKABLE void dbConnect();
    21.  
    22. Q_INVOKABLE void archiveDbConnect();
    23.  
    24. Q_INVOKABLE void sqlSelect(QString tableName);
    25.  
    26. Q_INVOKABLE void createDailyTable(QString tableName);
    27.  
    28. public slots:
    29.  
    30. void searchDateText(const QString &dateIn);
    31.  
    32. void searchUserNameText(const QString &userNameIn);
    33.  
    34. void archiveEvent();
    35.  
    36. void searchDateRange(const QString &beginDate, const QString &endDate);
    37.  
    38. void searchDateRange(const QString &userName, const QString &beginDate, const QString &endDate);
    39.  
    40. private:
    41. QList<userEventLogMsg> m_msgList;
    42. QSqlDatabase m_selectDataBase;
    43. QSqlDatabase m_archiveDataBase;
    44. QSqlQuery m_selectQuery;
    45. };
    To copy to clipboard, switch view to plain text mode 


    Added after 48 minutes:


    going to try attaching database to existing connection

    Qt Code:
    1. void sqliteModel::archiveEvent(){
    2. dbConnect();
    3. //archiveDbConnect();
    4.  
    5. QSqlQuery archiveDataQry(m_selectDataBase);
    6. archiveDataQry.prepare("ATTACH DATABASE '/home/amet/userLogArchive.db' as db2");
    7. archiveDataQry.exec();
    8.  
    9. if(archiveDataQry.exec()){
    10. qDebug()<<"sql statement exicuted fine";
    11. }
    12. else{
    13. qDebug() << "Errors accured with sql statement";
    14. qDebug() << archiveDataQry.lastError();
    15. }
    16.  
    17. m_selectDataBase.transaction();
    18. archiveDataQry.prepare("INSERT INTO 'db2.usereventarchive' SELECT * FROM main.usereventlog7");
    19.  
    20. if(archiveDataQry.exec()){
    21. qDebug()<<"copy sql statement exicuted fine";
    22. }
    23. else{
    24. qDebug() << "Errors accured with copy sql statement";
    25. qDebug() << archiveDataQry.lastError();
    26. }
    27.  
    28. m_selectDataBase.commit();
    29. m_selectDataBase.close();
    30. }
    To copy to clipboard, switch view to plain text mode 


    Added after 7 minutes:


    been trying to copy table contents from one database table to a separate database table but having issue with sql statement.

    I have a database connection established already and I'm trying to attach another database to that connection but not sure If I have the attach sql script correct....

    I get error "unable to fetch row", "No Qry"

    Qt Code:
    1. void sqliteModel::archiveEvent(){
    2. dbConnect();
    3.  
    4. QSqlQuery archiveDataQry(m_selectDataBase);
    5. archiveDataQry.prepare("ATTACH DATABASE '/home/amet/userLogArchive.db' as db2");
    6.  
    7. if(archiveDataQry.exec()){
    8. qDebug()<<"sql statement exicuted fine";
    9. }
    10. else{
    11. qDebug() << "Errors accured with sql statement";
    12. qDebug() << archiveDataQry.lastError();
    13. }
    14.  
    15. m_selectDataBase.transaction();
    16. archiveDataQry.prepare("INSERT INTO db2.usereventarchive SELECT * FROM main.usereventlog7");
    17.  
    18. if(archiveDataQry.exec()){
    19. qDebug()<<"copy sql statement exicuted fine";
    20. }
    21. else{
    22. qDebug() << "Errors accured with copy sql statement";
    23. qDebug() << archiveDataQry.lastError();
    24. }
    25.  
    26. m_selectDataBase.commit();
    27. m_selectDataBase.close();
    28. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by jfinn88; 13th September 2016 at 00:25.

  9. #49
    Join Date
    Dec 2009
    Location
    New Orleans, Louisiana
    Posts
    791
    Thanks
    13
    Thanked 153 Times in 150 Posts
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Re: using an isntance of QSqlDatabase for connection defiinition

    Quote Originally Posted by jfinn88 View Post
    I get error "unable to fetch row", "No Qry"
    Not clear at all which line of code produces that output, so please be specific regarding the error you're receiving and which line of code produces it...

    A couple of other general comments about your code. QSqlQuery::prepare returns a bool, don't ignore the return value and assume everything worked. You also seem to be changing your table names from example to example, so I have no clue if you're using the right table names from the main database, same for your archive database. Double check those names to ensure you are specifying tables that exist and have the expected number of columns, etc.

    Edit: Other portions of your post don't make any sense, i.e. you are using QSqlQuery::bindValue when your SQL statement has no positional or named arguments???
    Last edited by jefftee; 13th September 2016 at 02:24.
    I write the best type of code possible, code that I want to write, not code that someone tells me to write!

  10. The following user says thank you to jefftee for this useful post:

    jfinn88 (13th September 2016)

  11. #50
    Join Date
    Jun 2016
    Posts
    99
    Thanks
    18
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: using an isntance of QSqlDatabase for connection defiinition

    Quote Originally Posted by jefftee View Post
    Not clear at all which line of code produces that output, so please be specific regarding the error you're receiving and which line of code produces it...
    its the sql exec that throws this error in the if condition
    Qt Code:
    1. if(archiveDataQry.exec()){
    2. qDebug()<<"copy sql statement exicuted fine";
    3. }
    4. else{
    5. qDebug() << "Errors accured with copy sql statement";
    6. qDebug() << archiveDataQry.lastError();
    7. }
    To copy to clipboard, switch view to plain text mode 

    A couple of other general comments about your code. QSqlQuery::prepare returns a bool, don't ignore the return value and assume everything worked. You also seem to be changing your table names from example to example, so I have no clue if you're using the right table names from the main database, same for your archive database. Double check those names to ensure you are specifying tables that exist and have the expected number of columns, etc.
    I messed around with the tablenames have them set now how I want them. The two databases are: userLog.db with table usereventlog7 and userLogArchive.db with table usereventarchive and there is only four fields id, userName eventMessage, dateTime, both tables are set up the same data types. databases and names are now setup correct

    Edit: Other portions of your post don't make any sense, i.e. you are using QSqlQuery::bindValue when your SQL statement has no positional or named arguments???
    I was trying to use two different connections at first and using the first connections query select values and binding them with the second connections insert statement.... I see what your saying doesn’t make sense with the prepare statement I have in the post above. Below is the statement I meant to include with that snippet of code but wasn't working

    Qt Code:
    1. void sqliteModel::archiveEvent(){
    2. dbConnect();
    3. archiveDbConnect();
    4.  
    5. QSqlQuery archiveDataQry("SELECT * FROM userlogevents7", m_selectDataBase);
    6. QSqlQuery copyDataQry(m_archiveDataBase);
    7.  
    8. QString id;
    9. QString userName;
    10. QString eventMessage;
    11. QDate dateTime;
    12.  
    13. if(archiveDataQry.exec()){
    14. qDebug()<<"sql statement exicuted fine";
    15. }
    16. else{
    17. qDebug() << "Errors accured with sql statement";
    18. qDebug() << archiveDataQry.lastError();
    19. }
    20.  
    21. m_selectDataBase.transaction();
    22.  
    23. copyDataQry.prepare("INSERT INTO userLogArchive.usereventarchive (id, userName, eventMessage, dateTime) VALUES (:id, :userName, :eventMessage, :dateTime) FROM userLog.userlogevents7");
    24.  
    25. while(archiveDataQry.next()){
    26. id = archiveDataQry.record().value(0).toString();
    27. userName = archiveDataQry.record().value(1).toString();
    28. eventMessage = archiveDataQry.record().value(2).toString();
    29. dateTime = archiveDataQry.record().value(3).toDate();
    30. copyDataQry.bindValue(0,id);
    31. copyDataQry.bindValue(1, userName);
    32. copyDataQry.bindValue(2, eventMessage);
    33. copyDataQry.bindValue(3, dateTime);
    34. if(copyDataQry.exec()){
    35. qDebug()<<"copy sql statement exicuted fine";
    36. }
    37. else{
    38. qDebug() << "Errors accured with copy sql statement";
    39. qDebug() << copyDataQry.lastError();
    40. }
    41. }
    42. m_selectDataBase.commit();
    43. m_selectDataBase.close();
    44. }
    To copy to clipboard, switch view to plain text mode 

    I tried setting it up using ATTACH DATABASE sqlite cmd but cant get it to work either get error on exec() in if condition for insert statement unable to fetch row
    Qt Code:
    1. void sqliteModel::archiveEvent(){
    2. dbConnect();
    3.  
    4. QSqlQuery archiveDataQry(m_selectDataBase);
    5. archiveDataQry.prepare("ATTACH DATABASE '/home/amet/userLogArchive.db' as db2");
    6.  
    7. if(archiveDataQry.exec()){
    8. qDebug()<<"sql statement exicuted fine";
    9. }
    10. else{
    11. qDebug() << "Errors accured with sql statement";
    12. qDebug() << archiveDataQry.lastError();
    13. }
    14.  
    15. m_selectDataBase.transaction();
    16. archiveDataQry.prepare("INSERT INTO db2.usereventarchive SELECT * FROM main.usereventlog7");
    17.  
    18. if(archiveDataQry.exec()){
    19. qDebug()<<"copy sql statement exicuted fine";
    20. }
    21. else{
    22. qDebug() << "Errors accured with copy sql statement";
    23. qDebug() << archiveDataQry.lastError();
    24. }
    25.  
    26. m_selectDataBase.commit();
    27. m_selectDataBase.close();
    28. }
    To copy to clipboard, switch view to plain text mode 


    Added after 6 minutes:


    update the issues seems to be in my prepare statement its not able to find my usereventlog7 table and not sure why......

    Qt Code:
    1. archiveDataQry.prepare("INSERT INTO db2.usereventarchive SELECT * FROM main.usereventlog7");
    To copy to clipboard, switch view to plain text mode 


    Added after 5 minutes:


    update noticed simple typo fixed an works fine now thanks for suggesting checking bool value of prepare statement!


    Added after 16 minutes:


    update: Okay I got both ways working and found my mistakes in both of them where issue with prepare statement I think I will use the attach database way cleaner faster less code

    ===two connection=====
    Qt Code:
    1. dbConnect();
    2. archiveDbConnect();
    3.  
    4. QSqlQuery archiveDataQry("SELECT * FROM userlogevents7", m_selectDataBase);
    5. QSqlQuery copyDataQry(m_archiveDataBase);
    6.  
    7. int id;
    8. QString userName;
    9. QString eventMessage;
    10. QDate dateTime;
    11.  
    12. if(archiveDataQry.exec()){
    13. qDebug()<<"sql statement exicuted fine";
    14. }
    15. else{
    16. qDebug() << "Errors accured with sql statement";
    17. qDebug() << archiveDataQry.lastError();
    18. }
    19.  
    20. m_selectDataBase.transaction();
    21.  
    22. if(copyDataQry.prepare("INSERT INTO usereventarchive (id, userName, eventMessage, dateTime) VALUES (:id, :userName, :eventMessage, :dateTime)"))
    23. {
    24. qDebug()<<"prepare sql statement exicuted fine";
    25. }
    26. else{
    27. qDebug() << "Errors accured with prepare sql statement";
    28. qDebug() << copyDataQry.lastError();
    29. }
    30.  
    31. while(archiveDataQry.next()){
    32. id = archiveDataQry.record().value(0).toInt();
    33. userName = archiveDataQry.record().value(1).toString();
    34. eventMessage = archiveDataQry.record().value(2).toString();
    35. dateTime = archiveDataQry.record().value(3).toDate();
    36. copyDataQry.bindValue(0,id);
    37. copyDataQry.bindValue(1, userName);
    38. copyDataQry.bindValue(2, eventMessage);
    39. copyDataQry.bindValue(3, dateTime);
    40. if(copyDataQry.exec()){
    41. qDebug()<<"copy sql statement exicuted fine";
    42. }
    43. else{
    44. qDebug() << "Errors accured with copy sql statement";
    45. qDebug() << copyDataQry.lastError();
    46. }
    47. }
    48. m_selectDataBase.commit();
    49. m_selectDataBase.close();
    50. }
    To copy to clipboard, switch view to plain text mode 

    ====ATTACH DATABASE====
    Qt Code:
    1. void sqliteModel::archiveEvent(){
    2. //---connect to DB---//
    3. dbConnect();
    4.  
    5. //---attach archive DB to connection---//
    6. QSqlQuery archiveDataQry(m_selectDataBase);
    7. archiveDataQry.prepare("ATTACH DATABASE '/home/amet/userLogArchive.db' as db2");
    8.  
    9. //---execute attach DB---//
    10. if(archiveDataQry.exec()){
    11. qDebug()<<"sql statement exicuted fine";
    12. }
    13. else{
    14. qDebug() << "Errors accured with sql statement";
    15. qDebug() << archiveDataQry.lastError();
    16. }
    17.  
    18. //---prepare sql copy---//
    19. if(archiveDataQry.prepare("INSERT INTO db2.usereventarchive SELECT * FROM main.userlogevents7")){
    20. qDebug()<<"prepare sql statement exicuted fine";
    21. }
    22. else{
    23. qDebug() << "Errors accured with prepare sql statement";
    24. qDebug() << archiveDataQry.lastError();
    25. }
    26.  
    27. //---execute sql copy---//
    28. if(archiveDataQry.exec()){
    29. qDebug()<<"copy sql statement exicuted fine";
    30. }
    31. else{
    32. qDebug() << "Errors accured with copy sql statement";
    33. qDebug() << archiveDataQry.lastError();
    34. }
    35.  
    36. //---commit & close---//
    37. m_selectDataBase.commit();
    38. m_selectDataBase.close();
    39. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by jfinn88; 13th September 2016 at 17:21.

  12. #51
    Join Date
    Jun 2016
    Posts
    99
    Thanks
    18
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: using an isntance of QSqlDatabase for connection defiinition

    update: here is my archive function works okay so far...

    Copies rows from one database table that are older than 30 days and stores them in another database table for archiving.

    Qt Code:
    1. void sqliteModel::archiveEvent(){
    2. //---connect to DB---//
    3. dbConnect();
    4.  
    5. //---attach archive DB to connection---//
    6. QSqlQuery archiveDataQry(m_selectDataBase);
    7. archiveDataQry.prepare("ATTACH DATABASE '/home/amet/userLogArchive.db' as db2");
    8.  
    9. //---execute attach DB---//
    10. if(archiveDataQry.exec()){
    11. qDebug()<<"sql statement exicuted fine";
    12. }
    13. else{
    14. qDebug() << "Errors accured with sql statement";
    15. qDebug() << archiveDataQry.lastError();
    16. }
    17.  
    18. m_selectDataBase.transaction();
    19.  
    20. //---get archive date vlaue--//
    21. QSqlQuery dateQry("SELECT * FROM userlogevents7", m_selectDataBase);
    22.  
    23. QString dateStr;
    24. QDate archiveDate = QDate::currentDate().addDays(-30);
    25. //QDate::fromString(archiveDate, "yyyy-MM-dd");
    26. qDebug() << "archiveDate: "+archiveDate.toString("yyyy-MM-dd");
    27.  
    28. bool prepareSqlBool;
    29. prepareSqlBool = archiveDataQry.prepare("INSERT INTO db2.usereventarchive SELECT * FROM main.userlogevents7 WHERE dateTime < ?");
    30. archiveDataQry.addBindValue(archiveDate);
    31.  
    32. //---prepare sql copy---//
    33. if(prepareSqlBool){
    34. qDebug()<<"prepare sql statement exicuted fine";
    35. }
    36. else{
    37. qDebug() << "Errors accured with prepare sql statement";
    38. qDebug() << archiveDataQry.lastError();
    39. }
    40.  
    41. //---execute sql copy---//
    42. if(archiveDataQry.exec()){
    43. qDebug()<<"copy sql statement exicuted fine";
    44. }
    45. else{
    46. qDebug() << "Errors accured with copy sql statement";
    47. qDebug() << archiveDataQry.lastError();
    48. }
    49.  
    50. //---delete old rows---//
    51. while(dateQry.next())
    52. {
    53. dateStr = dateQry.value(3).toString();
    54. QDate rowDate = QDate::fromString(dateStr, "yyyy-MM-dd");
    55. //qDebug() << "results: "+rowDate.toString();
    56.  
    57. if(rowDate < archiveDate){
    58. qWarning() << rowDate;
    59. qDebug() << archiveDate;
    60. qDebug() << "made inside delete condition: ";
    61.  
    62. archiveDataQry.prepare("DELETE FROM userlogevents7 WHERE dateTime < ?");
    63. archiveDataQry.addBindValue(archiveDate);
    64.  
    65. //---execute delete---//
    66. if(archiveDataQry.exec()){
    67. qDebug()<<"delete sql statement exicuted fine";
    68. }
    69. else{
    70. qDebug() << "Errors accured with delete sql statement";
    71. qDebug() << archiveDataQry.lastError();
    72. }
    73. }
    74. else{
    75. qDebug() << "no old records to delte";
    76. }
    77. }
    78.  
    79. //---commit & close---//
    80. m_selectDataBase.commit();
    81. m_selectDataBase.close();
    82. }
    To copy to clipboard, switch view to plain text mode 

  13. #52
    Join Date
    Jun 2016
    Posts
    99
    Thanks
    18
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: using an isntance of QSqlDatabase for connection defiinition

    having issue hiding and showing my calendar objects using if condition inside a mouseArea onclicked I set the calendar visibility to false and set it true onClciked however i cant get it to hide after showing.....

    update: okay never mind just tried it again seems to be working able to show and hide calendar based of visible property and if condition

    Qt Code:
    1. ColumnLayout {
    2. id: calendarColumnLayout
    3. x: 8
    4. y: 54
    5. width: 259
    6. height: 540
    7. Rectangle {
    8. id: calendarRect1
    9. width: 247
    10. height: 247
    11. anchors.top: parent.top
    12. visible: false
    13. Calendar {
    14. id: calendar1
    15. width: 247
    16. height: 247
    17. anchors.rightMargin: -11
    18. anchors.bottomMargin: -8
    19. anchors.leftMargin: 2
    20. anchors.topMargin: 8
    21. anchors.fill: parent
    22. anchors.top: parent.top
    23. style: CalendarStyle {
    24. dayDelegate: Item {
    25. Rectangle {
    26. id: rect1
    27. anchors.fill: parent
    28. Label {
    29. id: dayDelegateText1
    30. text: styleData.date.getDate()
    31. anchors.centerIn: parent
    32. horizontalAlignment: Text.AlignRight
    33. font.pixelSize: Math.min(parent.height/3, parent.width/3)
    34. color: styleData.selected ? "red" : "black"
    35. font.bold: styleData.selected
    36. }
    37. MouseArea {
    38. anchors.horizontalCenter: parent.horizontalCenter
    39. anchors.verticalCenter: parent.verticalCenter
    40. width: styleData.selected ? parent.width / 2 : 0
    41. height: styleData.selected ? parent.height / 2 : 0
    42. Rectangle {
    43. anchors.fill: parent
    44. color: "transparent"
    45. border.color: "darkorange"
    46. }
    47. }
    48. }
    49. }
    50. }
    51. }
    52. }
    53. Rectangle {
    54. id: calendarRect2
    55. x: 14
    56. y: 350
    57. width: 247
    58. height: 247
    59. anchors.bottomMargin: -11
    60. anchors.bottom: parent.bottom
    61. visible: false
    62. Calendar {
    63. id: calendar2
    64. width: 247
    65. height: 247
    66. anchors.rightMargin: -5
    67. anchors.bottomMargin: 28
    68. anchors.leftMargin: -5
    69. anchors.topMargin: -28
    70. anchors.fill: parent
    71. anchors.bottom: parent.bottom
    72. style: CalendarStyle {
    73. dayDelegate: Item {
    74. Rectangle {
    75. id: rect2
    76. anchors.fill: parent
    77. Label {
    78. id: dayDelegateText2
    79. text: styleData.date.getDate()
    80. anchors.centerIn: parent
    81. horizontalAlignment: Text.AlignRight
    82. font.pixelSize: Math.min(parent.height/3, parent.width/3)
    83. color: styleData.selected ? "red" : "black"
    84. font.bold: styleData.selected
    85. }
    86. MouseArea {
    87. anchors.horizontalCenter: parent.horizontalCenter
    88. anchors.verticalCenter: parent.verticalCenter
    89. width: styleData.selected ? parent.width / 2 : 0
    90. height: styleData.selected ? parent.height / 2 : 0
    91. Rectangle {
    92. anchors.fill: parent
    93. color: "transparent"
    94. border.color: "darkorange"
    95. }
    96. onClicked: {
    97. //---emit the submitBegnDate signal---//
    98. //sqliteModel.searchDateRange();
    99. }
    100. }
    101. }
    102. }
    103. }
    104. }
    105. }
    106. }
    107. Label {
    108. id: calendarLabel
    109. x: 73
    110. y: 8
    111. text: qsTr("Select Date Range")
    112. }
    113.  
    114. Label {
    115. id: endDatelabel
    116. x: 104
    117. y: 309
    118. text: qsTr("End Date")
    119. MouseArea {
    120. id: endDateLabelMouseArea
    121. anchors.fill: parent
    122. onClicked: {
    123. if(calendarRect2.visible == false)
    124. {
    125. calendarRect2.visible = true
    126. }
    127. else {
    128. calendarRect2.visible = false
    129. }
    130. }
    131. }
    132. }
    133.  
    134. Label {
    135. id: beginDatelabel
    136. x: 97
    137. y: 31
    138. text: qsTr("Begin Date")
    139. MouseArea {
    140. id: beginDateLabelMouseArea
    141. anchors.fill: parent
    142. onClicked: {
    143. if(calendarRect1.visible == false)
    144. {
    145. calendarRect1.visible = true
    146. }
    147. else {
    148. calendarRect1.visible = false
    149. }
    150. }
    151. }
    152. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by jfinn88; 14th September 2016 at 00:23.

  14. #53
    Join Date
    Dec 2009
    Location
    New Orleans, Louisiana
    Posts
    791
    Thanks
    13
    Thanked 153 Times in 150 Posts
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Re: using an isntance of QSqlDatabase for connection defiinition

    Quote Originally Posted by jfinn88 View Post
    update: here is my archive function works okay so far...

    Copies rows from one database table that are older than 30 days and stores them in another database table for archiving.
    You should abort/rollback the transaction if you have an error with the insert for example, you would not want to continue and delete those records from the source table if they were not properly inserted into the archive table. While you do test success/failure you are only issuing success/failure messages but continue to fall through code to the next step, etc.
    I write the best type of code possible, code that I want to write, not code that someone tells me to write!

  15. #54
    Join Date
    Jun 2016
    Posts
    99
    Thanks
    18
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: using an isntance of QSqlDatabase for connection defiinition

    Quote Originally Posted by jefftee View Post
    You should abort/rollback the transaction if you have an error with the insert for example, you would not want to continue and delete those records from the source table if they were not properly inserted into the archive table. While you do test success/failure you are only issuing success/failure messages but continue to fall through code to the next step, etc.
    Thanks for bringing this up, I noticed this as well just a little bit ago and I'm using an if condition to check to make sure the insert sql statement gets executed correctly so it only executes delete if copy goes threw... here is updated code not sure if its the best way but it seem to be working fine wont delete tell copy is complete... I'll have to look into "abort/rollback" I have never done this before... I'm guessing you would jsut call the function in the else part of the clause
    Qt Code:
    1. m_selectDataBase.rollBack();
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. void UserEventLog::archiveEvent(){
    2. //---connect to DB---//
    3. dbConnect();
    4.  
    5. //---attach archive DB to connection---//
    6. QSqlQuery attachDbQry(m_selectDataBase);
    7. attachDbQry.prepare("ATTACH DATABASE '/home/amet/git/rnd/userLogArchive.db' as db2");
    8.  
    9. //---execute attach DB---//
    10. if(attachDbQry.exec()){
    11. qDebug()<<"sql statement exicuted fine";
    12. }
    13. else{
    14. qDebug() << "Errors accured with sql statement";
    15. qDebug() << attachDbQry.lastError();
    16. }
    17.  
    18. //---start DB transaction---//
    19. m_selectDataBase.transaction();
    20.  
    21. //---get archive date vlaue--//
    22. QSqlQuery dateQry("SELECT * FROM userlogevents", m_selectDataBase);
    23.  
    24. //---get currentDate minus 30days---//
    25. QString dateStr;
    26. QDate archiveDate = QDate::currentDate().addDays(-30);
    27. qDebug() << "archiveDate: "+archiveDate.toString("yyyy-MM-dd");
    28.  
    29. //---copy from one Db table to another---//
    30. QSqlQuery copyDataQry(m_selectDataBase);
    31. bool prepareSqlBool;
    32. prepareSqlBool = copyDataQry.prepare("INSERT INTO db2.userlogarchive (userName, eventMessage, dateTime) SELECT userName, eventMessage, dateTime FROM main.userlogevents WHERE dateTime < ?");
    33. copyDataQry.addBindValue(archiveDate);
    34.  
    35. //---prepare sql copy---//
    36. if(prepareSqlBool){
    37. qDebug()<<"prepare sql statement exicuted fine";
    38. }
    39. else{
    40. qDebug() << "Errors accured with prepare sql statement";
    41. qDebug() << copyDataQry.lastError();
    42. }
    43.  
    44. bool copySqlBool;
    45. copySqlBool = copyDataQry.exec();
    46.  
    47. //---execute sql copy---//
    48. if(copySqlBool){
    49. qDebug()<<"copy sql statement exicuted fine";
    50. }
    51. else{
    52. qDebug() << "Errors accured with copy sql statement";
    53. qDebug() << copyDataQry.lastError();
    54. }
    55.  
    56. QSqlQuery archiveDataQry(m_selectDataBase);
    57. QDate rowDate;
    58.  
    59. //---Copy rows to archive then delete old rows---//
    60. while(dateQry.next()){
    61. //---Get date value from dateQry---//
    62. dateStr = dateQry.value(3).toString();
    63. rowDate = QDate::fromString(dateStr, "yyyy-MM-dd");
    64.  
    65.  
    66. //---bool sql copy---//
    67. if(copySqlBool){
    68. //qDebug()<<"copy sql statement exicuted fine";
    69.  
    70. //---Executes only if copy qry executes---//
    71. if(rowDate < archiveDate){
    72. //qWarning() << rowDate;
    73. //qDebug() << archiveDate;
    74. //qDebug() << "made inside delete condition: ";
    75.  
    76. //---Sql delete statement---//
    77. archiveDataQry.prepare("DELETE FROM userlogevents WHERE dateTime < ?");
    78. archiveDataQry.addBindValue(archiveDate);
    79.  
    80. //---execute delete---//
    81. if(archiveDataQry.exec()){
    82. qDebug()<<"delete sql statement exicuted fine";
    83. }
    84. else{
    85. qDebug() << "Errors accured with delete sql statement";
    86. qDebug() << archiveDataQry.lastError();
    87. }
    88. }
    89. else{
    90. //qDebug() << "no old records to delte";
    91. //m_selectDataBase.rollBack();
    92. }
    93. }
    94. else{
    95. qDebug() << "Errors accured with copy sql statement";
    96. qDebug() << archiveDataQry.lastError();
    97. }
    98. }
    99.  
    100. //---commit transaction & close---//
    101. m_selectDataBase.commit();
    102. m_selectDataBase.close();
    103. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by jfinn88; 14th September 2016 at 23:33.

  16. #55
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,536
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: using an isntance of QSqlDatabase for connection defiinition

    I read the whole story and the question arises: is SQLite mandatory or you can use another database ?

  17. #56
    Join Date
    Jun 2016
    Posts
    99
    Thanks
    18
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: using an isntance of QSqlDatabase for connection defiinition

    I have been asked to do this in Sqlite3 I believe its used in another part of the project. I believe we pick sqlite for this project because it gets embedded inside the application, and do to its speed and efficiency is a better choice and we dont need different user to access the DB. This has been a good project for me because I don’t have much experience with C++ and have never used Qt frame work, IDE or QML


    Added after 1 26 minutes:


    I want to emit a mesageBox if any errors our thrown but messageBox is not showing up... calling it in my c++ fcn

    ===userEventLog.h====
    Qt Code:
    1. signals:
    2. void alertMsg(int icon, QString title, QString message);
    To copy to clipboard, switch view to plain text mode 

    and then call it like this but when I run the program messageBox wont display.... is there a stack setting needs to be set to 1 or something to put it on top level ?

    ====userEventLog.cpp====
    Qt Code:
    1. emit alertMsg(QMessageBox::Warning, "Error pulling data from database...", "message");
    To copy to clipboard, switch view to plain text mode 

    need to connect signal in qml I tried

    ====UserEventDialog===
    Qt Code:
    1. signal alertMsg(int icon, string title, string msg_text)
    2.  
    3. //---Get error here---//
    4. onAlertMsg: {
    5. msgDialog.text = msg_text
    6. msgDialog.title = title
    7. msgDialog.icon = icon
    8. msgDialog.open()
    9. }
    10.  
    11. Connections{
    12. target: UserEventLog
    13. onAlertMsg:{
    14. alertDialog.msg_text = msg_text
    15. alertDialog.title = title
    16. alertDialog.icon = icon
    17. viewRect.state = "ALERT"
    18.  
    19. }
    20. }
    21.  
    22. states: [
    23. State {
    24. name: "ALERT"
    25. PropertyChanges {target: userevent_item; enabled: false; opacity: .7}
    26. PropertyChanges {target: alertDialog; visible: true}
    27. }
    28. ]
    29.  
    30. AlertDialog{
    31. id: alertDialog
    32. anchors.verticalCenterOffset: -75
    33. anchors.horizontalCenterOffset: -50
    34. title: "Alert"
    35. msg_text: ""
    36. icon: 1
    37. onClose:{
    38. viewRect.state = ""
    39.  
    40. }
    41. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by jfinn88; 16th September 2016 at 00:41.

  18. #57
    Join Date
    Jun 2016
    Posts
    99
    Thanks
    18
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: using an isntance of QSqlDatabase for connection defiinition

    update: cleaned up qml code was getting confused on signal based off example I was using had dead code in it ...

    ====qml==========
    Qt Code:
    1. Connections{
    2. target: UserEventLog
    3. onAlertDbMsg:{
    4. alertDialog.msg_text = msg_text
    5. alertDialog.title = title
    6. alertDialog.icon = icon
    7. view_rect.state = "ALERT"
    8. console.log("made it inside alert");
    9. }
    10. }
    11.  
    12. states: [
    13. State {
    14. name: "ALERT"
    15. PropertyChanges {target: view_rect; enabled: false; opacity: .7;}
    16. PropertyChanges {target: alertDialog; visible: true;}
    17.  
    18. }
    19. ]
    20.  
    21. AlertDialog{
    22. id: alertDialog
    23. anchors.verticalCenterOffset: -75
    24. anchors.horizontalCenterOffset: -50
    25. title: "Alert"
    26. msg_text: ""
    27. icon: 1
    28. onClose:{
    29. view_rect.state = ""
    30. }
    31. }
    To copy to clipboard, switch view to plain text mode 

    =====c++=====
    Qt Code:
    1. emit alertDbMsg(QMessageBox::Warning, "Database Error Message", "Error pulling data from database...");
    To copy to clipboard, switch view to plain text mode 

    =====header file=====
    Qt Code:
    1. signals:
    2. void alertDbMsg(int icon, QString title, QString msg_text);
    To copy to clipboard, switch view to plain text mode 

  19. #58
    Join Date
    Jun 2016
    Posts
    99
    Thanks
    18
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: using an isntance of QSqlDatabase for connection defiinition

    not able to get a border around my table view ?

    Qt Code:
    1. Rectangle {
    2. id: tableViewRect
    3. width: 880
    4. height: 490
    5. anchors.verticalCenter: parent.verticalCenter
    6. anchors.left: parent.left
    7. anchors.leftMargin: 10
    8. border.width: 10
    9. border.color: "lightsteelblue"
    10. color: "transparent"
    11. TableView {
    12. id: tableView
    13. anchors.fill: parent
    14. sortIndicatorVisible: true
    15. sortIndicatorOrder: 1
    16. sortIndicatorColumn: 1
    17. frameVisible: true
    18. model: UserEventLog
    19. style: TableViewStyle {
    20. // frame: Rectangle {
    21. // border.color: "lightsteelblue"
    22. // border.width: 50
    23. // }
    24. headerDelegate: Rectangle {
    25. height: textItem.implicitHeight * 1.2
    26. width: textItem.implicitWidth
    27. color: "lightsteelblue"
    28. Text {
    29. id: textItem
    30. anchors.centerIn: parent
    31. text: styleData.value
    32. }
    33. Rectangle {
    34. anchors.right: parent.right
    35. anchors.top: parent.top
    36. anchors.bottom: parent.bottom
    37. width: 3
    38. color: "yellow"
    39. }
    40. }
    41. }
    42. TableViewColumn {
    43. role: "id"
    44. title: "id"
    45. width: 100
    46. }
    47. TableViewColumn {
    48. role: "userName"
    49. title: "User Name"
    50. width: 200
    51. }
    52. TableViewColumn {
    53. role: "eventMessage"
    54. title: "Event Message"
    55. width: 372
    56. }
    57. TableViewColumn {
    58. role: "dateTime"
    59. title: "Date Time"
    60. width: 201
    61. }
    62. }
    63. }
    To copy to clipboard, switch view to plain text mode 

  20. #59
    Join Date
    Jun 2016
    Posts
    99
    Thanks
    18
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: using an isntance of QSqlDatabase for connection defiinition

    found a solution: just messed around with my outer object rectangle and anchoring got a border around my tableView now! I made the rectangle little larger than tableView then enter tableView in the Rect.

    Qt Code:
    1. Rectangle {
    2. width: 880
    3. height: 490
    4. anchors.verticalCenter: parent.verticalCenter
    5. anchors.left: parent.left
    6. anchors.leftMargin: 10
    7. color: "transparent"
    8. radius: 7
    9. border.color: "lightsteelblue"
    10. border.width: 5
    11. visible: true
    12. TableView {
    13. id: tableView
    14. width: 870
    15. height: 480
    16. anchors.centerIn: parent
    17. sortIndicatorVisible: true
    18. sortIndicatorOrder: 1
    19. sortIndicatorColumn: 1
    20. //frameVisible: true
    21. model: UserEventLog
    22. style: TableViewStyle {
    23. headerDelegate: Rectangle {
    24. height: textItem.implicitHeight * 1.2
    25. width: textItem.implicitWidth
    26. color: "lightsteelblue"
    27. Text {
    28. id: textItem
    29. anchors.centerIn: parent
    30. text: styleData.value
    31. }
    32. Rectangle {
    33. anchors.right: parent.right
    34. anchors.top: parent.top
    35. anchors.bottom: parent.bottom
    36. width: 3
    37. color: "yellow"
    38. }
    39. }
    40. }
    41. TableViewColumn {
    42. role: "id"
    43. title: "id"
    44. width: 100
    45. }
    46. TableViewColumn {
    47. role: "userName"
    48. title: "User Name"
    49. width: 200
    50. }
    51. TableViewColumn {
    52. role: "eventMessage"
    53. title: "Event Message"
    54. width: 372
    55. }
    56. TableViewColumn {
    57. role: "dateTime"
    58. title: "Date Time"
    59. width: 201
    60. }
    61. }
    62. }
    To copy to clipboard, switch view to plain text mode 

  21. #60
    Join Date
    Dec 2009
    Location
    New Orleans, Louisiana
    Posts
    791
    Thanks
    13
    Thanked 153 Times in 150 Posts
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Re: using an isntance of QSqlDatabase for connection defiinition

    You may have better success starting new threads for different subjects.
    I write the best type of code possible, code that I want to write, not code that someone tells me to write!

Similar Threads

  1. Replies: 16
    Last Post: 4th September 2013, 01:49
  2. How to set x509 on a QSqlDatabase Connection?
    By m3rlin in forum Qt Programming
    Replies: 24
    Last Post: 21st February 2012, 05:04
  3. Windows OCI QSqlDatabase connection
    By hollyberry in forum Newbie
    Replies: 10
    Last Post: 13th February 2012, 23:13
  4. QSqlDatabase Connection Close on Destruction
    By Sanuden in forum Qt Programming
    Replies: 1
    Last Post: 1st September 2011, 16:32
  5. QSqlDatabase connection timeout?
    By joseprl89 in forum Qt Programming
    Replies: 6
    Last Post: 27th March 2011, 03:43

Tags for this Thread

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.