Results 1 to 4 of 4

Thread: About Progress bar

  1. #1
    Join Date
    Sep 2015
    Posts
    2
    Qt products
    Qt5
    Platforms
    Windows

    Default About Progress bar

    I have a class that contains ProgressBar. On another interface when I pressed the button, it will perform the reading of data and pour on the board. I will call it class ProgressBarbar to display the time it made it finished I will close the progress bar behind you. I do not know why sometimes the progress bar was run forever made without closing it. It appears with a low rate. Expect people to explain me, maybe because I use the progress bar wrong.

    code this:

    Qt Code:
    1. void TopMenu::onbtLoadData_clicked()
    2. {
    3.  
    4. if(mDialog==NULL)
    5. {
    6. mDialog= new ThanhDialogTable(NULL);
    7. mDialog->exec();
    8. delete mDialog;
    9. mDialog = NULL;
    10. }
    11. }
    To copy to clipboard, switch view to plain text mode 

    class ThanhDialogTable:
    Qt Code:
    1. ThanhDialogTable::ThanhDialogTable(QWidget *parent):
    2. QDialog(parent),
    3. ui(new Ui::ThanhDialogTable)
    4. {
    5. ui->setupUi(this);
    6. QFuture<void> *m_future = new QFuture<void>;
    7. m_SimpleProgress = new SimpleProgressBar();
    8. m_SimpleProgress->SetContent("Load Data......");
    9. *m_future = QtConcurrent::run(ThanhDialogTable::loadData, m_SimpleProgress);
    10. m_SimpleProgress->exec();
    11. }
    To copy to clipboard, switch view to plain text mode 


    and loadData of ThanhDialogTable
    Qt Code:
    1. bool ThanhDialogTable::loadData(FiSK_SimpleProgressBar *pProgress)
    2. {
    3. /* Here I call to read data to get one list data from the database and then
    4.   I put that data into the table and display */
    5. QString select("No, Name1, Name2");
    6. QStringList labels = select.split(", ");
    7. ui->m_table->setColumnCount(labels.count());
    8. ui->m_table->setHorizontalHeaderLabels(labels);
    9. QList<int> columnWidths;
    10. columnWidths << 49 << 129 << 99;
    11. ui->m_table->setColumnWidth(ColumnType::No, columnWidths[ColumnType::No]);
    12. ui->m_table->setColumnWidth(ColumnType::Name1, columnWidths[ColumnType::Name1]);
    13. ui->m_table->setColumnWidth(ColumnType::Name2, columnWidths[ColumnType::Name2]);
    14. QTableWidgetItem *item_name1;
    15. QTableWidgetItem *item_name2 ;
    16. QTableWidgetItem *item_No;
    17. int count = m_ListData.size();
    18. ui->m_table->setRowCount(count);
    19.  
    20. for (int i = 0; i < count; i++)
    21. {
    22. item_name1 = new QTableWidgetItem ();
    23. item_name2 = new QTableWidgetItem ( );
    24. item_No = new QTableWidgetItem ( );
    25. item_No ->setText(QString::number(i+1));
    26. item_name1->setText(m_ListData.at(i).mName1);
    27. item_name2->setText(m_ListData.at(i).mName2);
    28. ui->m_table->setItem(i,0,item_No);
    29. ui->m_table->setItem(i,1,item_name1);
    30. ui->m_table->setItem(i,2,item_name2);
    31. }
    32.  
    33. //Close progress bar
    34. pProgress->hide();
    35. pProgress->close();
    36. }
    To copy to clipboard, switch view to plain text mode 

    Please help me and sympathetic English in the level.
    Last edited by anda_skoa; 13th September 2015 at 08:36. Reason: changed [quote] to [code]

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: About Progress bar

    You are dealing with a multi threaded execution here.
    If the loading has finished before the progressbar executes, it will execute and never get the call to close.

    The code is also violating the rule to never use UI resources, such as widgets, from a secondary thread.
    This could crash at any time.

    There is also at least one memory leak: the first QFuture instance.

    Cheers,
    _

  3. #3
    Join Date
    Sep 2015
    Posts
    2
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: About Progress bar

    Quote Originally Posted by anda_skoa View Post
    You are dealing with a multi threaded execution here.
    If the loading has finished before the progressbar executes, it will execute and never get the call to close.

    The code is also violating the rule to never use UI resources, such as widgets, from a secondary thread.
    This could crash at any time.

    There is also at least one memory leak: the first QFuture instance.

    Cheers,
    _
    Thank Cheers!
    Because I want to have an interface of progess bar is displayed, so I use a class that contains QProgressBar of Qt. You can offer a better solution for me?

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: About Progress bar

    QProgressBar is fine, not related to your problem at all.

    Cheers,
    _

Similar Threads

  1. progress bar in QThreads
    By jackajack01 in forum Qt Programming
    Replies: 2
    Last Post: 25th August 2012, 00:43
  2. How to use progress bar
    By bijay in forum Newbie
    Replies: 1
    Last Post: 28th March 2012, 10:44
  3. How to use progress bar
    By Ashwani in forum Newbie
    Replies: 6
    Last Post: 10th September 2010, 15:19
  4. Replies: 4
    Last Post: 11th March 2008, 11:44
  5. Reg - Progress bar
    By suresh in forum Qt Programming
    Replies: 1
    Last Post: 12th December 2006, 15:11

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.