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. Problem with GUI
Qt 6.11 is out! See what's new in the release blog

Problem with GUI

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 Posters 1.0k Views 2 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.
  • R Offline
    R Offline
    rohan22
    wrote on last edited by
    #1

    heu guys i am new to this.i created my first gui for arduino uno..but i don't know how to save it permanently as a".exe" file. and bigger issue iis..after somtimes it stops responding.sorry for bad English
    here is diialog code.
    .```
    #include "dialog.h"
    #include "ui_dialog.h"
    #include <QSerialPort>
    #include <QSerialPortInfo>
    #include <QDebug>
    #include<QtWidgets>
    #include <string>
    #include <QMessageBox>
    Dialog::Dialog(QWidget *parent) :
    QDialog(parent),

    ui(new Ui::Dialog)
    

    {
    ui->setupUi(this);
    ui->main_altitude->display("-------");
    ui->lcdNumber_2->display("-------");
    ui->lcdNumber_3->display("-------");
    ui->lcdNumber_4->display("-------");
    ui->lcdNumber_5->display("-------");
    arduino_is_available=false;
    arduino =new QSerialPort;
    serialBuffer=" ";

    qDebug()<<"number of ports"<<QSerialPortInfo::availablePorts().length();
    foreach (const QSerialPortInfo &serialPortInfo,QSerialPortInfo::availablePorts()) {
        qDebug()<<"Has vendor id:"<<serialPortInfo.hasVendorIdentifier();
        if(serialPortInfo.hasVendorIdentifier())
           {
            qDebug()<<"vendor ID"<<serialPortInfo.vendorIdentifier();
    
        }
        qDebug()<<"has product id:"<<serialPortInfo.hasProductIdentifier();
        if(serialPortInfo.hasProductIdentifier())
        {
            qDebug()<<"Peroduct ID"<<serialPortInfo.productIdentifier();
        }
    }
    
    
    foreach(const QSerialPortInfo &serialPortInfo,QSerialPortInfo::availablePorts())  //to check avaliable or not
    {
        if(serialPortInfo.hasVendorIdentifier()&&serialPortInfo.hasProductIdentifier())
        {
              if(serialPortInfo.vendorIdentifier()==arduino_uno_vendor_id||serialPortInfo.vendorIdentifier()== xbee_vendor_id||serialPortInfo.vendorIdentifier()==arduino_uno_vendor_id1||serialPortInfo.vendorIdentifier()==vid)
              {
                  if(serialPortInfo.productIdentifier()==arduino_uno_product_id||serialPortInfo.productIdentifier()== xbee_product_id||serialPortInfo.productIdentifier()==arduino_uno_product_id1||serialPortInfo.productIdentifier()==pid)
                   {
                      arduino_port_name=serialPortInfo.portName();
                      arduino_is_available=true;
                  }
    
    
              }
        }
    }
    if(arduino_is_available)    // to open port
    {
        //to check
    

    arduino->setPortName(arduino_port_name);
    arduino->open(QSerialPort::ReadWrite);
    arduino->setBaudRate(QSerialPort::Baud9600);
    arduino->setDataBits(QSerialPort::Data8);
    arduino->setParity(QSerialPort::NoParity);
    arduino->setStopBits(QSerialPort::OneStop);
    arduino->setFlowControl(QSerialPort::NoFlowControl);
    QObject::connect(arduino,SIGNAL(readyRead()),this,SLOT(readserial()));

    }else
    {
       QMessageBox::warning(this,"port error","not found");
    
    }
    

    }

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

    void Dialog::readserial() // to take readings
    {

    bufferspilt=serialBuffer.split(",");
    if(bufferspilt.length()<3)
    {
    serialData=arduino->readAll();
    serialBuffer+=QString::fromStdString(serialData.toStdString());
    }
    else
    {
    qDebug()<<bufferspilt;
    Dialog::updateLCD(bufferspilt[1]);
    serialBuffer="";
    }
    }

    void Dialog::updateLCD(const QString sensor) // main screen
    {
    ui->main_altitude->display(sensor);

    }
    void Dialog::updateLCD1(const QString sensor)
    {
    ui->lcdNumber_2->display(sensor);
    }
    void Dialog::updateLCD2(const QString sensor)
    {
    ui->lcdNumber_3->display(sensor);
    }
    void Dialog::updateLCD3(const QString sensor)
    {
    ui->lcdNumber_4->display(sensor);
    }
    void Dialog::updateLCD4(const QString sensor)
    {
    ui->lcdNumber_5->display(sensor);
    }

    void Dialog::updateButton(QString command) // updating servo function
    {
    if(arduino->isWritable())
    {
    arduino->write(command.toStdString().c_str());
    }
    else{
    qDebug()<<"couldnt write to serial";
    }
    }

    void Dialog::on_all_servo_button_clicked() //all servo
    {

    Dialog::updateButton(QString("1"));
    //Dialog::updateLCD1(bufferspilt[1]);
    //serialBuffer="";
    }

    void Dialog::on_pushButton_2_clicked() //servo1
    {
    Dialog::updateButton(QString("2"));
    //Dialog::updateLCD2(bufferspilt[1]);
    //serialBuffer="";
    }

    void Dialog::on_pushButton_clicked() //servo2
    {
    Dialog::updateButton(QString("3"));
    // Dialog::updateLCD3(bufferspilt[1]);
    // serialBuffer="";

    }

    void Dialog::on_pushButton_3_clicked() //reseting servo
    {
    Dialog::updateButton(QString("4"));
    //Dialog::updateLCD4(bufferspilt[1]);
    // serialBuffer="";

    }

    header file down
    

    #ifndef DIALOG_H
    #define DIALOG_H

    #include <QDialog>
    #include <QSerialPort>

    namespace Ui {
    class Dialog;
    }

    class Dialog : public QDialog
    {
    Q_OBJECT

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

    private slots:
    void on_all_servo_button_clicked();
    void updateButton(QString );

    void on_pushButton_2_clicked();
    
    void on_pushButton_clicked();
    
    void on_pushButton_3_clicked();
    
    void readserial();
    void updateLCD(const QString);
     void updateLCD1(const QString);
      void updateLCD2(const QString);
       void updateLCD3(const QString);
        void updateLCD4(const QString);
    

    private:
    Ui::Dialog *ui;
    QSerialPort *arduino;
    static const quint16 arduino_uno_vendor_id=9025;
    static const quint16 arduino_uno_product_id=67;
    static const quint16 xbee_product_id=24577;
    static const quint16 xbee_vendor_id=1027;
    static const quint16 arduino_uno_vendor_id1=9025;
    static const quint16 arduino_uno_product_id1=67;
    static const quint16 vid=4292;
    static const quint16 pid=60000;
    QString arduino_port_name;
    bool arduino_is_available;
    QString serialBuffer;
    QByteArray serialData;
    QStringList bufferspilt;
    };

    #endif // DIALOG_H

    thank you guys for helping me!!!!
    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      What do you mean by "save it permanently as an exe" ? If you can run your application then it's already an executable.

      As for your bug, you should run a debug build and break when you see it's getting locked.

      Note that you are also not checking whether the serial port opening is successful.

      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
      2
      • R Offline
        R Offline
        rohan22
        wrote on last edited by
        #3

        when i am building program in release mode it is not showing any error but in debug mode t is showing error with <QSerialPort> header file

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

          What exact error are you getting ?

          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
          0

          • Login

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