Problem with GUI



  • 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!!!!

  • Lifetime Qt Champion

    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.



  • 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


  • Lifetime Qt Champion

    What exact error are you getting ?


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.