Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How can i store the values?
Qt 6.11 is out! See what's new in the release blog

How can i store the values?

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 3 Posters 710 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • lordumuzcaL Offline
    lordumuzcaL Offline
    lordumuzca
    wrote on last edited by
    #1

    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;
    
    }
    
    
    
    T 1 Reply Last reply
    0
    • lordumuzcaL lordumuzca

      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;
      
      }
      
      
      
      T Offline
      T Offline
      Tikani
      wrote on last edited by Tikani
      #2

      @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.

      1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #3

        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";
            }
        
        }
        

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        1

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved