문제

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

도움이 되었습니까?

해결책

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();

}

다른 팁

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top