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. Cannot output a value using QSerialPort
Forum Updated to NodeBB v4.3 + New Features

Cannot output a value using QSerialPort

Scheduled Pinned Locked Moved Unsolved General and Desktop
55 Posts 8 Posters 4.7k Views 4 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.
  • J jude.bato

    I just need to receive from the serial port, with the new syntax it requires a sender, &sender function which I cannot use / don't need

    Pablo J. RoginaP Offline
    Pablo J. RoginaP Offline
    Pablo J. Rogina
    wrote on last edited by
    #8

    @jude-bato said in Cannot output a value using QSerialPort:

    he new syntax it requires a sender, &sender function which I cannot use / don't need

    Please please take some time to read the link suggested for @Christian-Ehrlicher and try to understand the concepts of signal & slot under Qt

    Tip 1 : sender is a Qt object, and is the sender of a signal; an object that under some conditions will emit (send) a signal
    Tip 2: your sender is arduino object

    Upvote the answer(s) that helped you solve the issue
    Use "Topic Tools" button to mark your post as Solved
    Add screenshots via postimage.org
    Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

    1 Reply Last reply
    1
    • J Offline
      J Offline
      jude.bato
      wrote on last edited by
      #9

      I was reviewing the link and with trial and error I began trying to implement the new syntax. Saying that, part of the QObject::connect requires const char *signal which I have no idea what that means.

      1 Reply Last reply
      0
      • J Offline
        J Offline
        jude.bato
        wrote on last edited by jude.bato
        #10

        Reading on the new syntax I updated my Qt version as a troubleshooting method and put in QObject::connect(arduino, &QSerialPort::readyRead, this, &Dialog::readSerial); and the Application output is no member named 'connect' in 'QDebug'. I'm very lost

        jsulmJ 1 Reply Last reply
        0
        • J jude.bato

          Reading on the new syntax I updated my Qt version as a troubleshooting method and put in QObject::connect(arduino, &QSerialPort::readyRead, this, &Dialog::readSerial); and the Application output is no member named 'connect' in 'QDebug'. I'm very lost

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #11

          @jude-bato Please show the code where you call connect()

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          J 1 Reply Last reply
          0
          • jsulmJ jsulm

            @jude-bato Please show the code where you call connect()

            J Offline
            J Offline
            jude.bato
            wrote on last edited by
            #12

            @jsulm QObject::connect(arduino, SIGNAL(readyRead), this, SLOT(readSerial())); This is where connect should be called, but with the new syntax I very confused on how I can connect and read from Arduino into Qt

            jsulmJ 1 Reply Last reply
            -1
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #13

              Hi,

              You signal specification is still wrong in the connect statement.

              In any case, as already requested several times: please post the current code you are using.

              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
              3
              • J jude.bato

                @jsulm QObject::connect(arduino, SIGNAL(readyRead), this, SLOT(readSerial())); This is where connect should be called, but with the new syntax I very confused on how I can connect and read from Arduino into Qt

                jsulmJ Offline
                jsulmJ Offline
                jsulm
                Lifetime Qt Champion
                wrote on last edited by
                #14

                @jude-bato Why do you post again your old connect() call (which is wrong because the signal is missing brackets - readyRead())?
                Please post the code where you call connect() with new syntax (without SIGNAL/SLOT) and not just the connect() call itself but also the surrounding code...

                https://forum.qt.io/topic/113070/qt-code-of-conduct

                1 Reply Last reply
                2
                • J Offline
                  J Offline
                  jude.bato
                  wrote on last edited by
                  #15

                  QObject::connect(arduino, &QSerialPort::readyRead, this, &Dialog::readSerial); This is the code line that I have integrated in my current project, I'm just not sure how to convert it to the new syntax. I was using the old code because in the original question I wanted to specify where I was talking about. I know it was wrong and I changed it already. The problem I'm having is with the new syntax.

                  jsulmJ Pablo J. RoginaP 2 Replies Last reply
                  0
                  • J jude.bato

                    QObject::connect(arduino, &QSerialPort::readyRead, this, &Dialog::readSerial); This is the code line that I have integrated in my current project, I'm just not sure how to convert it to the new syntax. I was using the old code because in the original question I wanted to specify where I was talking about. I know it was wrong and I changed it already. The problem I'm having is with the new syntax.

                    jsulmJ Offline
                    jsulmJ Offline
                    jsulm
                    Lifetime Qt Champion
                    wrote on last edited by
                    #16

                    @jude-bato And with that code line you get "no member named 'connect' in 'QDebug'"?

                    https://forum.qt.io/topic/113070/qt-code-of-conduct

                    1 Reply Last reply
                    0
                    • J jude.bato

                      QObject::connect(arduino, &QSerialPort::readyRead, this, &Dialog::readSerial); This is the code line that I have integrated in my current project, I'm just not sure how to convert it to the new syntax. I was using the old code because in the original question I wanted to specify where I was talking about. I know it was wrong and I changed it already. The problem I'm having is with the new syntax.

                      Pablo J. RoginaP Offline
                      Pablo J. RoginaP Offline
                      Pablo J. Rogina
                      wrote on last edited by
                      #17

                      @jude-bato said in Cannot output a value using QSerialPort:

                      This is the code line

                      If you're looking for some help in the forum please make others' life easier.
                      Why is so difficult to show some code snippet of yours? not just ONE line.
                      Come on, some context helps understand what might be going on with your issue.

                      Upvote the answer(s) that helped you solve the issue
                      Use "Topic Tools" button to mark your post as Solved
                      Add screenshots via postimage.org
                      Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

                      1 Reply Last reply
                      4
                      • J Offline
                        J Offline
                        jude.bato
                        wrote on last edited by
                        #18

                        This is the code snippet, its in my dialog.cpp file

                        if(arduino_is_available)
                            {
                                qDebug()<<"Found the port \n";
                                arduino->setPortName(arduino_uno_port_name);
                                arduino->open(QSerialPort::ReadOnly);
                                arduino->setBaudRate(QSerialPort::Baud9600);
                                arduino->setDataBits(QSerialPort::Data8);
                                arduino->setFlowControl(QSerialPort::NoFlowControl);
                                arduino->setParity(QSerialPort::NoParity);
                                arduino->setStopBits(QSerialPort::OneStop);
                                connect(*arduino, Dialog::readSerial(updateVoltage()),this,readSerial()); //too few arguments to function call, expected 1, have 0
                            } else {
                                qDebug()<<"Could not find the correct port \n";
                                QMessageBox::information(this,"Serial Port Error", "Could not open the serial port");
                            }
                        }
                        

                        and the read serial code I have:

                        void Dialog::readSerial()
                        {
                            QStringList buffer_split = serialBuffer.split(",");
                            if(buffer_split.length() < 3)
                            {
                                serialData = arduino->readAll();
                                serialBuffer = serialBuffer + QString::fromStdString(serialData.toStdString());
                                serialData.clear();
                            } else {
                                serialBuffer = "";
                                qDebug() << buffer_split << "\n";
                                parsed_data = buffer_split[1];
                                voltage_value = (parsed_data.toDouble()) - 0.1;
                                qDebug() << "Voltage: " << voltage_value << "\n";
                                parsed_data = QString::number(voltage_value,'g',4);
                                Dialog::updateVoltage(parsed_data);
                            }
                        }
                        
                        Pablo J. RoginaP 1 Reply Last reply
                        0
                        • SGaistS Offline
                          SGaistS Offline
                          SGaist
                          Lifetime Qt Champion
                          wrote on last edited by
                          #19

                          Hi,

                          One thing that is missing: you don't check that the open call is successful. You should add that.

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

                          J 1 Reply Last reply
                          2
                          • J jude.bato

                            This is the code snippet, its in my dialog.cpp file

                            if(arduino_is_available)
                                {
                                    qDebug()<<"Found the port \n";
                                    arduino->setPortName(arduino_uno_port_name);
                                    arduino->open(QSerialPort::ReadOnly);
                                    arduino->setBaudRate(QSerialPort::Baud9600);
                                    arduino->setDataBits(QSerialPort::Data8);
                                    arduino->setFlowControl(QSerialPort::NoFlowControl);
                                    arduino->setParity(QSerialPort::NoParity);
                                    arduino->setStopBits(QSerialPort::OneStop);
                                    connect(*arduino, Dialog::readSerial(updateVoltage()),this,readSerial()); //too few arguments to function call, expected 1, have 0
                                } else {
                                    qDebug()<<"Could not find the correct port \n";
                                    QMessageBox::information(this,"Serial Port Error", "Could not open the serial port");
                                }
                            }
                            

                            and the read serial code I have:

                            void Dialog::readSerial()
                            {
                                QStringList buffer_split = serialBuffer.split(",");
                                if(buffer_split.length() < 3)
                                {
                                    serialData = arduino->readAll();
                                    serialBuffer = serialBuffer + QString::fromStdString(serialData.toStdString());
                                    serialData.clear();
                                } else {
                                    serialBuffer = "";
                                    qDebug() << buffer_split << "\n";
                                    parsed_data = buffer_split[1];
                                    voltage_value = (parsed_data.toDouble()) - 0.1;
                                    qDebug() << "Voltage: " << voltage_value << "\n";
                                    parsed_data = QString::number(voltage_value,'g',4);
                                    Dialog::updateVoltage(parsed_data);
                                }
                            }
                            
                            Pablo J. RoginaP Offline
                            Pablo J. RoginaP Offline
                            Pablo J. Rogina
                            wrote on last edited by
                            #20

                            @jude-bato said in Cannot output a value using QSerialPort:

                            connect(*arduino, Dialog::readSerial(updateVoltage()),this,readSerial());

                            Again, please read the documentation regarding signal and slots. You may want to try this article as well.

                            Tip: a typical connect sentence has 4 elements, try to identify such elements within your code...

                            Dialog::updateVoltage(parsed_data);

                            Do you know why you're calling an static method here?

                            Upvote the answer(s) that helped you solve the issue
                            Use "Topic Tools" button to mark your post as Solved
                            Add screenshots via postimage.org
                            Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

                            J 1 Reply Last reply
                            4
                            • SGaistS SGaist

                              Hi,

                              One thing that is missing: you don't check that the open call is successful. You should add that.

                              J Offline
                              J Offline
                              jude.bato
                              wrote on last edited by
                              #21

                              @SGaist I believe I do

                              bool arduino_is_available = false;
                                  QString arduino_uno_port_name;
                                  foreach(const QSerialPortInfo &serialPortInfo, QSerialPortInfo::availablePorts()){
                                      if(serialPortInfo.hasProductIdentifier() && serialPortInfo.hasVendorIdentifier()){
                                          if((serialPortInfo.productIdentifier() == arduino_uno_product_id) && (serialPortInfo.vendorIdentifier() == arduino_uno_vendor_id)){
                                              arduino_is_available = true;
                                              arduino_uno_port_name = serialPortInfo.portName();
                                          }
                                      }
                                  }
                              
                                  if(arduino_is_available)
                                  {
                                      qDebug()<<"Found the port \n";
                                      arduino->setPortName(arduino_uno_port_name);
                                      arduino->open(QSerialPort::ReadOnly);
                                      arduino->setBaudRate(QSerialPort::Baud9600);
                                      arduino->setDataBits(QSerialPort::Data8);
                                      arduino->setFlowControl(QSerialPort::NoFlowControl);
                                      arduino->setParity(QSerialPort::NoParity);
                                      arduino->setStopBits(QSerialPort::OneStop);
                                      QObject::connect(arduino, SIGNAL(readyRead), this, SLOT(readSerial())); //I know this is wrong, this is what I'm trying to fix
                                  } else {
                                      qDebug()<<"Could not find the correct port \n";
                                      QMessageBox::information(this,"Serial Port Error", "Could not open the serial port");
                                  }
                              }
                              
                              1 Reply Last reply
                              0
                              • Christian EhrlicherC Online
                                Christian EhrlicherC Online
                                Christian Ehrlicher
                                Lifetime Qt Champion
                                wrote on last edited by
                                #22

                                @jude-bato said in Cannot output a value using QSerialPort:

                                I believe I do

                                No, you don't check the value of QSerialPoort::open(). And you should set the parameter before opening the device.

                                Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                                Visit the Qt Academy at https://academy.qt.io/catalog

                                1 Reply Last reply
                                3
                                • Pablo J. RoginaP Pablo J. Rogina

                                  @jude-bato said in Cannot output a value using QSerialPort:

                                  connect(*arduino, Dialog::readSerial(updateVoltage()),this,readSerial());

                                  Again, please read the documentation regarding signal and slots. You may want to try this article as well.

                                  Tip: a typical connect sentence has 4 elements, try to identify such elements within your code...

                                  Dialog::updateVoltage(parsed_data);

                                  Do you know why you're calling an static method here?

                                  J Offline
                                  J Offline
                                  jude.bato
                                  wrote on last edited by
                                  #23

                                  @Pablo-J-Rogina I've already tried with the new syntax and I've tried with different elements and I keep getting the expected 1, have 0 output. As for the parsed_data I personally have never used it but I used Vannevar Morgan code as reference and it worked (https://github.com/vannevar-morgan/Qt-Temperature-Sensor/blob/master/DS18B20_Qt/dialog.cpp)

                                  @Christian-Ehrlicher Then I'm not sure how to go about doing so, I thought that mean to check if the port on the Arduino is open. When debugging I tested throughout my code and was open the Serial Port and read an open port on the Arduino, the only issue is I can't read anything from it

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

                                    How did you test that ?

                                    As for the call to open: again, always check that it succeeded. You might be trying to use an already opened device or you don't have the rights to open said device. Therefore, add that check before going further.

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

                                    J 1 Reply Last reply
                                    2
                                    • SGaistS SGaist

                                      How did you test that ?

                                      As for the call to open: again, always check that it succeeded. You might be trying to use an already opened device or you don't have the rights to open said device. Therefore, add that check before going further.

                                      J Offline
                                      J Offline
                                      jude.bato
                                      wrote on last edited by
                                      #25

                                      @SGaist I have

                                      Dialog::~Dialog()
                                      {
                                          if(arduino->isOpen())
                                          {
                                              arduino->close();
                                          }
                                          delete ui;
                                      }
                                      

                                      Would this satisfy the QSerialPort::open()?

                                      Also would I need to use connect? I change that line to just readSerial(); but I'm not able to implement void Dialog::updateVoltage(QString sensor_reading) into if(arduino_is_available)

                                      jsulmJ 1 Reply Last reply
                                      0
                                      • J jude.bato

                                        @SGaist I have

                                        Dialog::~Dialog()
                                        {
                                            if(arduino->isOpen())
                                            {
                                                arduino->close();
                                            }
                                            delete ui;
                                        }
                                        

                                        Would this satisfy the QSerialPort::open()?

                                        Also would I need to use connect? I change that line to just readSerial(); but I'm not able to implement void Dialog::updateVoltage(QString sensor_reading) into if(arduino_is_available)

                                        jsulmJ Offline
                                        jsulmJ Offline
                                        jsulm
                                        Lifetime Qt Champion
                                        wrote on last edited by jsulm
                                        #26

                                        @jude-bato said in Cannot output a value using QSerialPort:

                                        Would this satisfy the QSerialPort::open()?

                                        Of course not, it does not have anything to do with open().

                                        if(!arduino->open(QSerialPort::ReadOnly)) {
                                            qDebug() << "Opening serial port failed";
                                            qDebug() << arduino->error() << arduino->errorString();
                                        }
                                        

                                        https://forum.qt.io/topic/113070/qt-code-of-conduct

                                        J 1 Reply Last reply
                                        5
                                        • jsulmJ jsulm

                                          @jude-bato said in Cannot output a value using QSerialPort:

                                          Would this satisfy the QSerialPort::open()?

                                          Of course not, it does not have anything to do with open().

                                          if(!arduino->open(QSerialPort::ReadOnly)) {
                                              qDebug() << "Opening serial port failed";
                                              qDebug() << arduino->error() << arduino->errorString();
                                          }
                                          
                                          J Offline
                                          J Offline
                                          jude.bato
                                          wrote on last edited by
                                          #27

                                          @jsulm Thank you for your suggestion, I put in your code and I ran it again. This is what I got:1.png I'm so confused why my program isn't working correctly. I have a feeling that my problem has to do with reading from or something with making a connection with Arduino rather than the Serial Port itself.

                                          Pablo J. RoginaP jsulmJ 2 Replies Last reply
                                          0

                                          • Login

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