What is the proper way to set QProgressBar to update from the logic layer?

孤街醉人 提交于 2019-12-18 19:02:45

问题


If I want to update a QProgressBar on the view layers from a loop on the logic layer (such as each iteration will update the progress bar), what is the proper way to do that?

Thanks


回答1:


class LogicClass : public QObject
{
    Q_OBJECT
public:
    explicit LogicClass(QObject *parent = 0);
    int max(){ return 100; }
    int min(){ return 0; }
    void emit50(){ emit signalProgress(50); }

signals:
    void signalProgress(int);

public slots:

};


MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    LogicClass logic;

    ui->progressBar->setMaximum( logic.max() );
    ui->progressBar->setMinimum( logic.min() );
    connect( &logic, SIGNAL( signalProgress(int) ), ui->progressBar, SLOT( setValue(int) ) );

    logic.emit50();

}



回答2:


QProgressBar has some public slots that are used for setting min and max values and current value. Increasing the current value causes the progress bar to move. You can emit a signal from the logic layer that is connected to "void setValue ( int value )" slot of QProgressBar. http://doc.qt.digia.com/qt/qprogressbar.html



来源:https://stackoverflow.com/questions/14230265/what-is-the-proper-way-to-set-qprogressbar-to-update-from-the-logic-layer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!