Results 1 to 6 of 6

Thread: QProgressBar: don't understand in details, help me !!!

  1. #1
    Join Date
    May 2007
    Posts
    10
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Unhappy QProgressBar: don't understand in details, help me !!!

    Hi all,

    I begin to write a simple application that load data from database and I want to use QProgressBar but I don't know exactly how it works, pls show it for me in details.

    Thanks in advance.

  2. #2
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QProgressBar: don't understand in details, help me !!!

    It is very easy to use one.
    Create it,put it in a layout, set it's max and min value, and then call setValue to update it.
    You also can look at QProgressDialog beacuse it uses a QProgressBar.

    Regards

  3. #3
    Join Date
    May 2007
    Posts
    10
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Question Re: QProgressBar: don't understand in details, help me !!!

    In my program, I want to connect to database that verify user input, please tell me how to make progressbar describe this progress.

    Beforehands thanks.

    Anh.

  4. #4
    Join Date
    Jan 2007
    Posts
    209
    Thanks
    34
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QProgressBar: don't understand in details, help me !!!

    Everything you need to know is simple:

    1) Create QProgressBar
    2) setMin setMAx
    3) setValue according to some sort of SIGNAL, like if database connected maybe connect a function to add like 20 more % to progressbar
    Take a look at examples in your Qt folder, like HTTP or FTP example.

  5. #5
    Join Date
    May 2006
    Posts
    788
    Thanks
    49
    Thanked 48 Times in 46 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QProgressBar: don't understand in details, help me !!!

    Quote Originally Posted by haconganh View Post
    In my program, I want to connect to database that verify user input, please tell me how to make progressbar describe this progress.

    Beforehands thanks.

    Anh.
    QProgressDialog *dlg = new QProgressDialog(0,Qt::Popup);

    here is a sample wo user can not stop dlg->setCancelButton(0); && query... result is a dump file

    Qt Code:
    1. void ExportSql()
    2. {
    3. if (OSWinServer()) {
    4. table = table.toUpper(); /* bastard win ! */
    5. }
    6.  
    7. QDate nowtaga = QDate::currentDate();
    8. bool ok;
    9. QString ba = nowtaga.toString("d.M.yyyy")+"_"+table+".sql";
    10.  
    11. QString cfileName = QFileDialog::getSaveFileName(this, "Export MYSQL table format",ba, "*.sql");
    12. if (cfileName.size() > 0 && cfileName !=ba ) {
    13. if (!cfileName.endsWith(".sql")) {
    14. cfileName = cfileName+".sql";
    15. }
    16. } else {
    17. return;
    18. }
    19.  
    20. QProgressDialog *dlg = new QProgressDialog(0,Qt::Popup);
    21. dlg->setLabelText (tr("Export table \"%1\" from %2").arg( table ).arg(db.hostName()));
    22. dlg->setCancelButton(0);
    23. //////dlg->setMaximum(100);
    24. //////dlg->setValue(0);
    25.  
    26.  
    27.  
    28. qDebug() << "### ExportSql " << table;
    29. QDate nowtag = QDate::currentDate();
    30. QSqlQuery query(QString("SELECT * FROM %1").arg(table),db);
    31. QSqlRecord rec = query.record();
    32. QStringList cvslines;
    33. QStringList Fname;
    34. QStringList Fvalue;
    35. cvslines.clear();
    36. cvslines.append(QString("\n###### table %1\n\n").arg(table));
    37. cvslines.append(QString("\n###### date %1\n\n").arg(nowtag.toString("d.M.yyyy")));
    38.  
    39. bool suppoaffect;
    40. int sumcol = rec.count();
    41. int sumrow = query.numRowsAffected();
    42. int recnum = 0; /* QProgressDialog *dlg; */
    43. int pasero = 0;
    44.  
    45.  
    46. while (query.next()) {
    47. recnum++; /* count fake lines */
    48. dlg->setMaximum(100);
    49. dlg->setValue((recnum * 100) / sumrow );
    50. Fvalue.clear();
    51. Fname.clear();
    52.  
    53. for(int i=0;i<sumcol;i++){
    54. bool oknr = false;
    55. QSqlField fld = rec.field(i);
    56. QString value = sql_Quote(query.value(i).toString());
    57. value = value.replace("\n","\\n");
    58. value = value.replace("\t","\\t");
    59. value = value.replace("\r","\\r");
    60. const QString typeoffield = QString(QVariant::typeToName(fld.type()));
    61. if ( typeoffield == "int" ) {
    62. int vnummer = value.toInt(&oknr);
    63. }
    64. QString fname = sql_Quote(rec.fieldName(i));
    65. if (oknr) {
    66. Fvalue.append(value);
    67. } else if (value.isEmpty()) {
    68. Fvalue.append(DefaultFieldFrom(table,fname));
    69. } else {
    70. Fvalue.append(QString("'%1'").arg(value));
    71. }
    72. }
    73.  
    74. QString Dvalue = Fvalue.join(",");
    75. cvslines.append(QString("REPLACE INTO %1 VALUES (%2);\n").arg(table).arg(Dvalue));
    76. }
    77. dlg->close();
    78.  
    79. cvslines.append(QString("\n"));
    80.  
    81.  
    82. QString stream = SqlCreateTable();
    83. stream.append(cvslines.join(""));
    84.  
    85. /////////qDebug() << "### stream " << stream;
    86. QFile f( cfileName );
    87. if ( f.open( QFile::WriteOnly | QFile::Text ) )
    88. {
    89. QTextStream sw( &f );
    90. sw << stream;
    91. f.close();
    92. } else {
    93. QMessageBox::warning(this, tr("Error SQL File!"),tr("Unable to write on this file ..."));
    94. }
    95.  
    96. }
    97.  
    98.  
    99. QString DefaultFieldFrom( const QString table , const QString field )
    100. {
    101. const QString xdefault = "NULL";
    102. QSqlQuery query(QString("SHOW COLUMNS FROM %1").arg(table),db_0);
    103. QSqlRecord rec = query.record();
    104. int sumcol = rec.count();
    105. while (query.next()) {
    106. QString feldname = query.value(0).toString();
    107. if ( feldname == field ) {
    108. QString svl = query.value(4).toString();
    109. if (svl.size() < 1) {
    110. return xdefault;
    111. } else {
    112. return svl;
    113. }
    114.  
    115. }
    116.  
    117. }
    118.  
    119. return xdefault;
    120. }
    To copy to clipboard, switch view to plain text mode 

  6. #6
    Join Date
    May 2007
    Posts
    10
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: QProgressBar: don't understand in details, help me !!!

    Hi patrik08,

    With your code, I understand it exactly now,
    thank patrik08 a lot

Similar Threads

  1. QProgressbar and ... Spacebar
    By RafalR in forum Qt Programming
    Replies: 6
    Last Post: 11th September 2006, 18:40
  2. setOrientation QProgressBar
    By fellobo in forum Qt Tools
    Replies: 4
    Last Post: 15th February 2006, 23:32
  3. QProgressBar & 200%
    By Dmitry in forum Qt Programming
    Replies: 2
    Last Post: 20th January 2006, 11:33

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.