如果我想从逻辑层上的循环更新视图层上的QProgressBar(例如每次迭代都会更新进度条),正确的方法是什么?
谢谢
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有一些公共槽,用于设置最小值、最大值和当前值。增加当前值会导致进度条移动。您可以从连接到QProgressBar的"void setValue (int value)"插槽的逻辑层发出信号。http://doc.qt.digia.com/qt/qprogressbar.html