Qwt实时拨号

时间:2015-05-14 15:25:10

标签: multithreading qt plot real-time qwt

我想创建一个只包含拨号的简单Qwt小部件。表盘上显示的值(即表盘的位置)应根据我从单独的线程收集的一些输入数据进行更新。

我可以在主窗口类中生成我的拨号,我可以在主窗口类的单独线程上创建和启动我的数据捕获,如下所示:

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()来更新表盘上显示的值?

1 个答案:

答案 0 :(得分:1)

我找到了答案 - 不知道这是否是最佳方式。

只需将指针传递给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方法更新拨号:

void DataClass::SetValue(int x)
{
    _pDial->setValue(x);

    return;
}

我已经为pDial指针省略了互斥锁等,但这些当然是必要的。