c++ - 如何将变量附加到 QTextEdit 控件

标签 c++ qt

我在 GUI 上有一个 QTextEdit 控件。我想以与在 C# 或 MFC 中相同的方式将其链接到控件,但无法完全找到命令。

基本上我有这个:

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();

private slots:

private:
    Ui::MainWindow *ui;
    QString fileName_;

    QMap<QString, unsigned int> vars_; // this is the data I want to associate
};

在 ui::MainWindow 类中我有:

class Ui_MainWindow
{
public:
    QWidget *centralWidget;
    QTextEdit *ALU;       // this is the control I want to associate with the data
.
.
.

我确信这很简单,但我看不出如何将 map 实例与 GUI 控件相关联。

我是瞎了眼还是 Qt 使用了不同的模式?

最佳答案

您可以使用 QTextEdit::textChanged() 信号。

class MainWindow : public QMainWindow
{
    Q_OBJECT
public:
    explicit MainWindow(QWidget *parent = 0) : QMainWindow(parent)
    {
        connect(ALU, SIGNAL(textChanged()), this, SLOT(updateVars()));
        ...
    }

private slots:
    void updateVars()
    {
        // do something with vars_
    }
};

关于c++ - 如何将变量附加到 QTextEdit 控件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29310980/

相关文章:

c++ - 抗锯齿像素渲染

C++ 模板编译器错误

C++ 加载文件

windows - Qt Creator 在自定义流程步骤中将命令名称放在引号内

c++ - Qt - 如何知道子部件中的内容是否已更改?

c++ - 如何在MPI-2+中复制MPI_Accumulate的功能

c++ - 如何使用 boost::optional

QTreeView清除选择

c++ - EnumDisplayDevices 函数对我不起作用

qt - Qt 样式表中的 'not equal to' 选择器是什么?