Unsolved How can i store the values?
-
I need to be store in horizontal slider values and i want to write when i push the button.but i cant store the values.if i store the values , i'll use in pushbutton. my output must be "value1,value2,value3".
#include "dialog.h" #include "ui_dialog.h" #include <QSerialPort> #include <QDebug> #include <QtWidgets> #include <QString> QSerialPort *serial; Dialog::Dialog(QWidget *parent) : QDialog(parent), ui(new Ui::Dialog) { ui->setupUi(this); serial = new QSerialPort(this); serial->setPortName("COM3"); serial->setBaudRate(QSerialPort::Baud9600); serial->setDataBits(QSerialPort::Data8); serial->setParity(QSerialPort::NoParity); serial->setStopBits(QSerialPort::OneStop); serial->setFlowControl(QSerialPort::NoFlowControl); serial->open(QIODevice::ReadWrite); connect(serial,SIGNAL(readyRead()),this,SLOT(serialReceived())); } Dialog::~Dialog() { delete ui; serial->close(); } void Dialog::on_degree_horizontalSlider_valueChanged(int value) { Dialog::updateServo(QString("%1,").arg()); } void Dialog::on_delay_horizontalSlider_valueChanged(int value) { Dialog::updateServo(QString("%1,").arg(value)); } void Dialog::on_rnumber_horizontalSlider_valueChanged(int value) { Dialog::updateServo(QString("%1").arg(value)); /*??*/ } void Dialog::on_pushButton_clicked() { //???? } void Dialog::updateServo(QString command) { if(serial->isWritable()){ serial->write(command.toStdString().c_str()); }else{ qDebug()<<"Couldn't write to serial"; } } void Dialog::serialReceived(){ QByteArray ba; serial->waitForReadyRead(10); ba=serial->readAll(); qDebug()<<ba; }
-
@lordumuzca
I didn't understand precisely what and where you want some values to store, but a general approach in such cases, as I think, is to sub-class the parent you need and add suitable fields. -
Hi,
If I understand things correctly, you want to always send the value of the three sliders ?
If so, you can drop the four on_XXX_ slots and connect all relevant widgets to updateServo from which you remove the parameter. Then:
id Dialog::updateServo() { if(serial->isWritable()){ QString cmd("%1,%2,%3").arg(ui.degree_horizontalSlider.value()) ui.arg(delay_horizontalSlider.value() ui.arg(rnumber_horizontalSlider.value() serial->write(cmd.toUtf8()); }else{ qDebug()<<"Couldn't write to serial"; } }