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. Regarding Projector Programming using QT
Forum Updated to NodeBB v4.3 + New Features

Regarding Projector Programming using QT

Scheduled Pinned Locked Moved Solved General and Desktop
30 Posts 5 Posters 3.5k 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.
  • P Offline
    P Offline
    Prath
    wrote on last edited by
    #6

    We are using a projector application to send command to the projector.

    1 Reply Last reply
    0
    • P Offline
      P Offline
      Prath
      wrote on last edited by
      #7

      However, I am not able to write anythinh in the window created after running the Qt programme

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

        Hi,

        Write what ?
        Write where ?
        In what window ?

        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
        • P Offline
          P Offline
          Prath
          wrote on last edited by
          #9

          Hey @SGaist , after running the above programme , a GUI pops out. We have to send a command to the projector using the GUI. However, I couldn't send any commnad as nothing could be written on the GUI window.

          Pablo J. RoginaP 1 Reply Last reply
          0
          • P Prath

            Hey @SGaist , after running the above programme , a GUI pops out. We have to send a command to the projector using the GUI. However, I couldn't send any commnad as nothing could be written on the GUI window.

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

            @Prath said in Regarding Projector Programming using QT:

            after running the above programme

            which program?
            The Serial Terminal example I suggested before?

            Have you tested managing the projector using any other terminal application? Just to validate it works fine...

            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
            0
            • P Offline
              P Offline
              Prath
              wrote on last edited by
              #11

              Yes. @Pablo-J-Rogina . I am connecting the projector to Quectel QCOM application. Now I want to skip that application and create my customised application to control the projector.

              I wrote a programme based on the guidelines of Quectel to switch off the projector. Following is the code. Even I used the QSerialPort code. But the projector couldn't switch off. However using the command prompt of the Quectel QCOM application, I could control the projector.

              main.cpp

              #include "mainwindow.h"

              #include <QApplication>

              int main(int argc, char *argv[])
              {
              QApplication a(argc, argv);
              MainWindow w;
              w.show();
              return a.exec();
              }

              mainwindow.cpp

              #include "mainwindow.h"
              #include "ui_mainwindow.h"
              #include <QDebug>
              #include<QSerialPort>
              #include<string>
              #include<QtGui>
              #include <QMessageBox>

              using namespace std;
              QSerialPort *serial;
              MainWindow::MainWindow(QWidget *parent)
              : QMainWindow(parent)
              , ui(new Ui::MainWindow)
              {
              ui->setupUi(this);
              }

              MainWindow::~MainWindow()
              {
              delete ui;
              }

              void MainWindow::on_pushButton_clicked()
              {
              QMessageBox::information(this,"Title here","Hello World");
              serial = new QSerialPort(this);
              serial->setPortName("COM3");
              serial->setBaudRate(QSerialPort::Baud115200,QSerialPort::AllDirections);
              serial->setDataBits(QSerialPort::Data8);
              serial->setFlowControl(QSerialPort::NoFlowControl);
              serial->setStopBits(QSerialPort::OneStop);
              serial->setParity(QSerialPort::NoParity);

              if(!serial->open(QIODevice::ReadWrite))
              {
                  qDebug()<<"error: can't open com port";
              }
              
              QString command = "WT+LEDE=0\n";
              QByteArray x = command.toLocal8Bit();
              serial->write(x);
              

              }

              mainwindow.h

              #ifndef MAINWINDOW_H
              #define MAINWINDOW_H

              #include <QMainWindow>

              QT_BEGIN_NAMESPACE
              namespace Ui { class MainWindow; }
              QT_END_NAMESPACE

              class MainWindow : public QMainWindow
              {
              Q_OBJECT

              public:
              MainWindow(QWidget *parent = nullptr);
              ~MainWindow();

              private slots:
              void on_pushButton_clicked();

              private:
              Ui::MainWindow *ui;
              };
              #endif // MAINWINDOW_H

              #-------------------------------------------------

              Project created by QtCreator 2019-11-02T10:55:21

              #-------------------------------------------------

              QT += core gui serialport

              greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

              TARGET = GUISerialPort
              TEMPLATE = app

              SOURCES += main.cpp
              mainwindow.cpp

              HEADERS += mainwindow.h

              FORMS += mainwindow.ui

              jsulmJ 1 Reply Last reply
              0
              • P Prath

                Yes. @Pablo-J-Rogina . I am connecting the projector to Quectel QCOM application. Now I want to skip that application and create my customised application to control the projector.

                I wrote a programme based on the guidelines of Quectel to switch off the projector. Following is the code. Even I used the QSerialPort code. But the projector couldn't switch off. However using the command prompt of the Quectel QCOM application, I could control the projector.

                main.cpp

                #include "mainwindow.h"

                #include <QApplication>

                int main(int argc, char *argv[])
                {
                QApplication a(argc, argv);
                MainWindow w;
                w.show();
                return a.exec();
                }

                mainwindow.cpp

                #include "mainwindow.h"
                #include "ui_mainwindow.h"
                #include <QDebug>
                #include<QSerialPort>
                #include<string>
                #include<QtGui>
                #include <QMessageBox>

                using namespace std;
                QSerialPort *serial;
                MainWindow::MainWindow(QWidget *parent)
                : QMainWindow(parent)
                , ui(new Ui::MainWindow)
                {
                ui->setupUi(this);
                }

                MainWindow::~MainWindow()
                {
                delete ui;
                }

                void MainWindow::on_pushButton_clicked()
                {
                QMessageBox::information(this,"Title here","Hello World");
                serial = new QSerialPort(this);
                serial->setPortName("COM3");
                serial->setBaudRate(QSerialPort::Baud115200,QSerialPort::AllDirections);
                serial->setDataBits(QSerialPort::Data8);
                serial->setFlowControl(QSerialPort::NoFlowControl);
                serial->setStopBits(QSerialPort::OneStop);
                serial->setParity(QSerialPort::NoParity);

                if(!serial->open(QIODevice::ReadWrite))
                {
                    qDebug()<<"error: can't open com port";
                }
                
                QString command = "WT+LEDE=0\n";
                QByteArray x = command.toLocal8Bit();
                serial->write(x);
                

                }

                mainwindow.h

                #ifndef MAINWINDOW_H
                #define MAINWINDOW_H

                #include <QMainWindow>

                QT_BEGIN_NAMESPACE
                namespace Ui { class MainWindow; }
                QT_END_NAMESPACE

                class MainWindow : public QMainWindow
                {
                Q_OBJECT

                public:
                MainWindow(QWidget *parent = nullptr);
                ~MainWindow();

                private slots:
                void on_pushButton_clicked();

                private:
                Ui::MainWindow *ui;
                };
                #endif // MAINWINDOW_H

                #-------------------------------------------------

                Project created by QtCreator 2019-11-02T10:55:21

                #-------------------------------------------------

                QT += core gui serialport

                greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

                TARGET = GUISerialPort
                TEMPLATE = app

                SOURCES += main.cpp
                mainwindow.cpp

                HEADERS += mainwindow.h

                FORMS += mainwindow.ui

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

                @Prath said in Regarding Projector Programming using QT:

                if(!serial->open(QIODevice::ReadWrite))

                Does open() succeed?

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

                P 1 Reply Last reply
                0
                • jsulmJ jsulm

                  @Prath said in Regarding Projector Programming using QT:

                  if(!serial->open(QIODevice::ReadWrite))

                  Does open() succeed?

                  P Offline
                  P Offline
                  Prath
                  wrote on last edited by
                  #13

                  @jsulm Yes. Open succeeded. But still, the projector could not read the commands which I am sending through serial port.

                  jsulmJ 1 Reply Last reply
                  0
                  • P Prath

                    @jsulm Yes. Open succeeded. But still, the projector could not read the commands which I am sending through serial port.

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

                    @Prath You should check what write() returns and connect a slot to https://doc.qt.io/qt-5/qserialport.html#errorOccurred to see whether you get any errors.

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

                    P 1 Reply Last reply
                    0
                    • jsulmJ jsulm

                      @Prath You should check what write() returns and connect a slot to https://doc.qt.io/qt-5/qserialport.html#errorOccurred to see whether you get any errors.

                      P Offline
                      P Offline
                      Prath
                      wrote on last edited by
                      #15

                      @jsulm Could you please help me with the syntax for checking the error. I am completely new in using this.

                      jsulmJ 1 Reply Last reply
                      0
                      • P Prath

                        @jsulm Could you please help me with the syntax for checking the error. I am completely new in using this.

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

                        @Prath You know how to connect a slot to a signal?
                        https://doc.qt.io/qt-5/signalsandslots.html

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

                        1 Reply Last reply
                        2
                        • P Offline
                          P Offline
                          Prath
                          wrote on last edited by Prath
                          #17

                          Yeah @jsulm . We have to connect this signal [signal]void QSerialPort::errorOccurred(QSerialPort::SerialPortError error) to the slot right?

                          Is this correct?
                          void MainWindow::errorReport(QSerialPort::SerialPortError error)
                          {
                          if(error!=0)
                          qDebug()<<"ERROR:"<<endl<<error; // nothing printed
                          }

                          connect(this->Serial,SIGNAL(error(QSerialPort::SerialPortError)),this,SLOT(errorReport(QSerialPort::SerialPortError)));

                          jsulmJ 1 Reply Last reply
                          0
                          • P Prath

                            Yeah @jsulm . We have to connect this signal [signal]void QSerialPort::errorOccurred(QSerialPort::SerialPortError error) to the slot right?

                            Is this correct?
                            void MainWindow::errorReport(QSerialPort::SerialPortError error)
                            {
                            if(error!=0)
                            qDebug()<<"ERROR:"<<endl<<error; // nothing printed
                            }

                            connect(this->Serial,SIGNAL(error(QSerialPort::SerialPortError)),this,SLOT(errorReport(QSerialPort::SerialPortError)));

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

                            @Prath said in Regarding Projector Programming using QT:

                            Is this correct?

                            Signal is https://doc.qt.io/qt-5/qserialport.html#errorOccurred not error. Just check the documentation.

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

                            1 Reply Last reply
                            3
                            • P Offline
                              P Offline
                              Prath
                              wrote on last edited by
                              #19

                              I think it is correct @jsulm. We are catching the signal using the slot and then displaying the signal.

                              JonBJ 1 Reply Last reply
                              0
                              • P Prath

                                I think it is correct @jsulm. We are catching the signal using the slot and then displaying the signal.

                                JonBJ Offline
                                JonBJ Offline
                                JonB
                                wrote on last edited by
                                #20

                                @Prath
                                You wrote

                                connect(this->Serial,SIGNAL(error(QSerialPort::SerialPortError)),this,SLOT(errorReport(QSerialPort::SerialPortError)));
                                

                                Where you have SIGNAL(error(QSerialPort::SerialPortError)) @jsulm is expecting SIGNAL(errorOccurred(QSerialPort::SerialPortError)). If what you have works, we do not understand how.

                                If you are writing new code and would change over to the new signal/slot syntax you would presumably receive a compile-time error.

                                1 Reply Last reply
                                2
                                • P Offline
                                  P Offline
                                  Prath
                                  wrote on last edited by
                                  #21

                                  Sorry for the delay guys. I tried again with the code and couldn't retrieve anything from the serial port regarding the errror.
                                  I got the attached error:-
                                  IMG_20191124_125954.jpg

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

                                    Your MainWindow class does not have such a signal, it's one from the QSerialPort.

                                    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
                                    • P Offline
                                      P Offline
                                      Prath
                                      wrote on last edited by
                                      #23

                                      Didnt get you @SGaist .
                                      Could you please help me with the syntax

                                      1 Reply Last reply
                                      0
                                      • P Offline
                                        P Offline
                                        Prath
                                        wrote on last edited by
                                        #24

                                        When I click on the push button the function on_pushButton_clicked is called and then I call the Qserialport to check the error. I think the code is written correctly.

                                        What's your take?

                                        jsulmJ 1 Reply Last reply
                                        0
                                        • P Prath

                                          When I click on the push button the function on_pushButton_clicked is called and then I call the Qserialport to check the error. I think the code is written correctly.

                                          What's your take?

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

                                          @Prath said in Regarding Projector Programming using QT:

                                          What's your take?

                                          Your connect is wrong: MainWindow does NOT have signal error(QSerialPort::QSerialPort), this signal is in QSerialPort, so not in "this" but in "serial".

                                          And please do not post screen-shots, copy paste your code...

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

                                          JonBJ 1 Reply Last reply
                                          3

                                          • Login

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