我试图实现默认按钮。此按钮应访问父窗口小部件的字符串,该窗口小部件是找到该按钮的对话框。我粘贴了下面代码的相关部分。我想要的是能够在单击默认值时将字符串放置到相应的lineEdit。例如,pulse_string进入ui-> pulse_freq,nr_pulsestring进入ui-> nr_pulses等。
#include "settings.h"
#include "ui_settings.h"
#include <QLineEdit>
#include <QSlider>
#include <QSpinBox>
int pulse_freq = 25000;
int nr_pulses = 10;
int samp_freq = 150000;
int nr_samples = 2000;
int gain = 32;
int accumulate = 1;
int acq_start = 0;
Settings::Settings(QWidget *parent) :
QDialog(parent),
ui(new Ui::Settings)
{
QString pulse_string, nr_pulsestring, sampfreq_string, nr_samplestring, gain_string;
QString accumulate_string, acq_string;
}
Settings::~Settings()
{
delete ui;
}
void Settings::on_Default_Values_clicked()
{
ui->pulse_freq->setText("25000");
ui->nr_pulses->setText("10");
ui->samp_freq->setText("150000");
ui->nr_samples->setText("2000");
ui->gain->setText("32");
ui->accumulate->setText("1");
ui->acq_start->setText("0");
}
答案 0 :(得分:0)
您可以使用如下内容:
ui->pulse_freq->setText(QString("%1").arg(pulse_freq));
由于您似乎只使用数字,因此最好使用旋转框插入值,因此您无需检查输入是否为有效数字等。