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. my application doesnt work:( can you help me to understand why?
Forum Updated to NodeBB v4.3 + New Features

my application doesnt work:( can you help me to understand why?

Scheduled Pinned Locked Moved Unsolved General and Desktop
c++commandusbterminal
14 Posts 3 Posters 1.2k Views
  • 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 RuWex

    @jsulm
    I did it because of a problem I had in my application- its Unfortunately, consumed
    this line in sendCommand.cpp doesnt work:

     MainSendCommand mainSend(letter.toLatin1());
     mainSend.ActivationMainWindow();
    

    I just want to remind what I have in mainSendCommand.cpp:

    MainSendCommand::MainSendCommand(QByteArray file)
    {
        sendCommand= new SendCommands();
        mainwind= new MainWindow();
        this->file= file;
    
    }
    void MainSendCommand::ActivationMainWindow()
    {
        mainwind->writeData(file);
    
    }
    
    jsulmJ Offline
    jsulmJ Offline
    jsulm
    Lifetime Qt Champion
    wrote on last edited by
    #4

    @RuWex said in my application doesnt work:( can you help me to understand why?:

    this line in sendCommand.cpp doesnt work

    There are two lines.
    And each of this lines involves other code. Please tell us what exactly does not work, I'm not a debugger...

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

    R 1 Reply Last reply
    0
    • jsulmJ jsulm

      @RuWex said in my application doesnt work:( can you help me to understand why?:

      this line in sendCommand.cpp doesnt work

      There are two lines.
      And each of this lines involves other code. Please tell us what exactly does not work, I'm not a debugger...

      R Offline
      R Offline
      RuWex
      wrote on last edited by
      #5

      @jsulm @jsulm
      mainwind->writeData(file);

      its not sent it to terminal and writedata()- this function work(I use it in other situation and it workes well)

      jsulmJ 1 Reply Last reply
      0
      • R RuWex

        @jsulm @jsulm
        mainwind->writeData(file);

        its not sent it to terminal and writedata()- this function work(I use it in other situation and it workes well)

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

        @RuWex What about adding error handling? A proper application should have it.
        For example: m_serial->write(data) has a return value with a meaning, you simply ignore it. And there is also https://doc.qt.io/qt-5/qserialport.html#error-prop
        Then you're blocking Qt event loop with your QThread::sleep(1), this can also break things.

        Why do you send these strings character by character instead whole string at once?

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

        1 Reply Last reply
        2
        • R Offline
          R Offline
          RuWex
          wrote on last edited by
          #7

          @jsulm
          -Why do you send these strings character by character instead whole string at once?

          because I have to make timer between any char,
          the camera need to get the command character by character with waiting between

          jsulmJ 1 Reply Last reply
          0
          • R RuWex

            @jsulm
            -Why do you send these strings character by character instead whole string at once?

            because I have to make timer between any char,
            the camera need to get the command character by character with waiting between

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

            @RuWex said in my application doesnt work:( can you help me to understand why?:

            the camera need to get the command character by character with waiting between

            Then you should rework your code. You should use a QTimer and on each timeout send next character. With your current approach you're blocking the event loop.
            And don't forget to add error handling...

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

            R 1 Reply Last reply
            2
            • jsulmJ jsulm

              @RuWex said in my application doesnt work:( can you help me to understand why?:

              the camera need to get the command character by character with waiting between

              Then you should rework your code. You should use a QTimer and on each timeout send next character. With your current approach you're blocking the event loop.
              And don't forget to add error handling...

              R Offline
              R Offline
              RuWex
              wrote on last edited by
              #9

              @jsulm
              I did it,
              before I load the code I took away all unrelevant line:

              void SendCommands::StartToSendCommand( QString fileName)//Ruth
              {
              
                  bool ans=additionalTest->CountsTheTimeRemaining(fileName);
                  if (ans)
                  {
                      QFile file(fileName);
                      if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
                          return;
              
              
                      QTextStream in(&file);
                      QString line;
                      while (!in.atEnd()) {
              
                          line = in.readLine();
                          if (line==""||line[0]=="#")
                              continue;
                 
                          for(int i=0; i< line.length(); ++i)
                          {
                              QString letter= (QString)line[i];
                              MainSendCommand mainSend(letter.toLatin1());
                              mainSend.ActivationMainWindow();
                              QThread::sleep(1);
              
                          }
                          qDebug()<<endl;
                          timer->start(GWaitingTimeBetweenCommand);
                          QApplication::processEvents();
                          QThread::sleep(2);
              
                      }
              
                  }
                  else {
                      return;
                  }
              
              }
              
              jsulmJ JonBJ 2 Replies Last reply
              0
              • R RuWex

                @jsulm
                I did it,
                before I load the code I took away all unrelevant line:

                void SendCommands::StartToSendCommand( QString fileName)//Ruth
                {
                
                    bool ans=additionalTest->CountsTheTimeRemaining(fileName);
                    if (ans)
                    {
                        QFile file(fileName);
                        if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
                            return;
                
                
                        QTextStream in(&file);
                        QString line;
                        while (!in.atEnd()) {
                
                            line = in.readLine();
                            if (line==""||line[0]=="#")
                                continue;
                   
                            for(int i=0; i< line.length(); ++i)
                            {
                                QString letter= (QString)line[i];
                                MainSendCommand mainSend(letter.toLatin1());
                                mainSend.ActivationMainWindow();
                                QThread::sleep(1);
                
                            }
                            qDebug()<<endl;
                            timer->start(GWaitingTimeBetweenCommand);
                            QApplication::processEvents();
                            QThread::sleep(2);
                
                        }
                
                    }
                    else {
                        return;
                    }
                
                }
                
                jsulmJ Offline
                jsulmJ Offline
                jsulm
                Lifetime Qt Champion
                wrote on last edited by
                #10

                @RuWex said in my application doesnt work:( can you help me to understand why?:

                I did it,

                What?
                QTimer to send characters? No, you did not!
                You start a timer after sending all the characters in the for loop...

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

                1 Reply Last reply
                2
                • R RuWex

                  @jsulm
                  I did it,
                  before I load the code I took away all unrelevant line:

                  void SendCommands::StartToSendCommand( QString fileName)//Ruth
                  {
                  
                      bool ans=additionalTest->CountsTheTimeRemaining(fileName);
                      if (ans)
                      {
                          QFile file(fileName);
                          if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
                              return;
                  
                  
                          QTextStream in(&file);
                          QString line;
                          while (!in.atEnd()) {
                  
                              line = in.readLine();
                              if (line==""||line[0]=="#")
                                  continue;
                     
                              for(int i=0; i< line.length(); ++i)
                              {
                                  QString letter= (QString)line[i];
                                  MainSendCommand mainSend(letter.toLatin1());
                                  mainSend.ActivationMainWindow();
                                  QThread::sleep(1);
                  
                              }
                              qDebug()<<endl;
                              timer->start(GWaitingTimeBetweenCommand);
                              QApplication::processEvents();
                              QThread::sleep(2);
                  
                          }
                  
                      }
                      else {
                          return;
                      }
                  
                  }
                  
                  JonBJ Online
                  JonBJ Online
                  JonB
                  wrote on last edited by
                  #11

                  @RuWex said in my application doesnt work:( can you help me to understand why?:

                          QThread::sleep(1);
                          QApplication::processEvents();
                          QThread::sleep(2);
                  

                  And in addition to @jsulm none of the above lines should be in your code any longer (when you get the timer right).

                  1 Reply Last reply
                  1
                  • R Offline
                    R Offline
                    RuWex
                    wrote on last edited by
                    #12

                    @RuWex said in my application doesnt work:( can you help me to understand why?:

                    timer->start(GWaitingTimeBetweenCommand);

                    I did it in the constructor:

                    SendCommands::SendCommands()
                    {
                        additionalTest= new DoAdditionalTest();
                        timer= new QTimer();
                    }
                    

                    void SendCommands::StartToSendCommand( QString fileName)//Ruth
                    {

                    bool ans=additionalTest->CountsTheTimeRemaining(fileName);
                    if (ans)
                    {
                        QFile file(fileName);
                        if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
                            return;
                    
                    
                        QTextStream in(&file);
                        QString line;
                        while (!in.atEnd()) {
                    
                            line = in.readLine();
                            if (line==""||line[0]=="#")
                                continue;
                    
                            for(int i=0; i< line.length(); ++i)
                            {
                                QString letter= (QString)line[i];
                                MainSendCommand mainSend(letter.toLatin1());
                                mainSend.ActivationMainWindow();
                                QThread::sleep(1);
                    
                            }
                            qDebug()<<endl;
                            **~~timer->start(GWaitingTimeBetweenCommand);~~**
                            QApplication::processEvents();
                            QThread::sleep(2);
                    
                        }
                    
                    }
                    else {
                        return;
                    }
                    

                    }

                    R 1 Reply Last reply
                    0
                    • R RuWex

                      @RuWex said in my application doesnt work:( can you help me to understand why?:

                      timer->start(GWaitingTimeBetweenCommand);

                      I did it in the constructor:

                      SendCommands::SendCommands()
                      {
                          additionalTest= new DoAdditionalTest();
                          timer= new QTimer();
                      }
                      

                      void SendCommands::StartToSendCommand( QString fileName)//Ruth
                      {

                      bool ans=additionalTest->CountsTheTimeRemaining(fileName);
                      if (ans)
                      {
                          QFile file(fileName);
                          if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
                              return;
                      
                      
                          QTextStream in(&file);
                          QString line;
                          while (!in.atEnd()) {
                      
                              line = in.readLine();
                              if (line==""||line[0]=="#")
                                  continue;
                      
                              for(int i=0; i< line.length(); ++i)
                              {
                                  QString letter= (QString)line[i];
                                  MainSendCommand mainSend(letter.toLatin1());
                                  mainSend.ActivationMainWindow();
                                  QThread::sleep(1);
                      
                              }
                              qDebug()<<endl;
                              **~~timer->start(GWaitingTimeBetweenCommand);~~**
                              QApplication::processEvents();
                              QThread::sleep(2);
                      
                          }
                      
                      }
                      else {
                          return;
                      }
                      

                      }

                      R Offline
                      R Offline
                      RuWex
                      wrote on last edited by RuWex
                      #13

                      @jsulm @JonB I dont understand what is my problem
                      can you explain me how to change the code and where?

                      JonBJ 1 Reply Last reply
                      0
                      • R RuWex

                        @jsulm @JonB I dont understand what is my problem
                        can you explain me how to change the code and where?

                        JonBJ Online
                        JonBJ Online
                        JonB
                        wrote on last edited by JonB
                        #14

                        @RuWex
                        Please look at the QTimer documentation, and the examples there. This does not work by "inserting a delay" into the code where it is called. Rather, it sets off a timer which keeps running, and you supply a "slot"/"callback" which will be invoked when the timer expires. It is in that function/lambda that you do whatever work you wish to perform each time the repeating or singleshot timer expires, e.g. in your case maybe it sends the next character.

                        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