2

I have class, that launches tasks in separate thread:

class SomeTask : public QObject, QRunnable
{
    Q_OBJECT
signals:
    void updateProgressBar(int, int);
public:
    SomeTask(int, QWidget*);
    void run();
    void runLongOperation(QString)
    {
        QThreadPool::globalInstance()->start(this);
    }
};

And in MainWindow I create for every long calculation new QProgressBar

class MainWindow : public QMainWindow
{
    Q_OBJECT
public:
    explicit MainWindow(QWidget *parent = 0);
private:
    QList<QProgressDialog*> m_listProgressDialogs;
public slots:
    void handle(QString) 
    {
          m_listProgressDialogs.push_back(new QProgressDialog("Task in progress...", "Cancel", 0, 100));
   m_listProgressDialogs.at(m_listProgressDialogs.size()-1)->show();

   SomeTask *task = new SomeTask(m_listProgressDialogs.size()-1, this);
   QObject::connect(mv, SIGNAL(updateProgressBar(int)), this, SLOT(setValueProgressBar(int)));
   task->runLongOperation(......);
    }
    void setValueProgressBar(int);
};

Is it possible to create new QProgressBar for every long task and every task will emit the signal to set value in specific QProgressBar. Is it good to store QProgressBar* in QList, like I wrote ?

Nikolay
  • 21
  • 1

0 Answers0