我想创建一个简单的Qwt小部件,只包含一个刻度盘。刻度盘上显示的值(即刻度盘的位置)应该根据我从单独线程收集的一些输入数据进行更新。
我可以在主窗口类中生成我的dial,并且可以在主窗口类中的单独线程上创建和启动数据捕获,如下所示:
MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent)
{
// create the dial
QDial* pDial = new QDial;
// create the data class to capture data from an external source
DataClass* pData = new DataClass;
// start the data class thread
pData->Start();
// I can get the latest value of data at any instant like this:
int x = pData->GetData();
// I need to connect the data value to the dial, so that the
// dial always displays the value of the data capture device.
}我可以插入什么,以便不断调用GetData()来更新刻度盘上显示的值?
发布于 2015-05-15 01:31:30
我想出了一个答案--不知道这是不是最好的方法。
只需将指向刻度盘的指针传递到DataClass的构造函数中:
DataClass* pData = new DataClass(pDial);在DataClass类中,包含一个QDial*成员和SetDialValue方法:
class DataClass
{
public:
Position(QDial* pDial);
.
.
.
void SetValue(int x);
private:
QDial* _pDial;
int _val;
}将_pDial设置为传入构造函数的指针,然后每当接收到新数据时,通过SetValue方法更新dial:
void DataClass::SetValue(int x)
{
_pDial->setValue(x);
return;
}我为pDial指针省略了互斥锁等,但这些当然是必要的。
https://stackoverflow.com/questions/30241138
复制相似问题