Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Normal c++ to qt c++
QtWS25 Last Chance

Normal c++ to qt c++

Scheduled Pinned Locked Moved Solved Mobile and Embedded
qt c++c++encoderraspberry pi 3main loop
9 Posts 5 Posters 4.3k 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.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by A Former User
    #1

    I have written a program in C++. I have tried that program in plain qt c++. That is working fine. Now I want to change my existing code. I am new for qt c++ I don't know how to add. I hope here I can get a solution.

    Existing Code: (Using wiringPi)

    Encoder Count.h

    #ifndef ENCODERCOUNT_H
    #define ENCODERCOUNT_H
    
    namespace Encoder {
    class EncoderCount;
    }
    
    class EncoderCount
    {
    public:
        explicit EncoderCount();
        ~EncoderCount();
    
        static int cycleleftinterrupt;
    
        int Left_Encoder_Read();
    
        bool Encoder_Pulse();
    };
    
    #endif
    

    Encodercount.cpp

    #define ENCODER_LEFT 14
    
    int Flag_LeftInterrupt=0;
    
    bool ResetFalseLeft;
    
    using namespace std;
    
    EncoderCount::EncoderCount()
    {
        pinMode(ENCODER_LEFT,INPUT);
        digitalWrite(ENCODER_LEFT, HIGH);
        ResetFalseLeft = false;
    }
    
    EncoderCount::~EncoderCount()
    {
    }
    
     int EncoderCount::Left_Encoder_Read()
    {
        return encoderValue/4;
    }
    
     void leftencoderinterrupt(void)
     {
    
    My stuff here............................
    
    encoderValue ++;
         if(sum .............)
     encoderValue --;
    
         lastEncoded = encoded; 
     }
    
    bool EncoderCount::Encoder_Pulse()
    {
        if(wiringPiISR(ENCODER_LEFT,INT_EDGE_BOTH,&leftencoderinterrupt)<0)
         {
            return false;
        }
        return true;
    }
    

    I have tried the new code that is working fine that I want to take from project main and I will include here. I don't know how to add/include. I am new to c++, so please help to get a solution. Here I have attached new code

    #include <pigpio.h>
    #include "rotary_encoder.hpp"
    #include <iostream>
    #include <stdio.h>
    #include <unistd.h>
    
    #include <QApplication>
    
    void callback(int way)
    {
       static int pos = 0;
       pos += way;
       std::cout << "pos=" << pos << std::endl;
    }
    
    int main(int argc, char *argv[])
    {
        QApplication a(argc, argv);
        Dialog w;
        w.show();
    
        if (gpioInitialise() < 0) return 1;
        re_decoder dec(8, 11, callback);
        sleep(50);
        dec.re_cancel();
        gpioTerminate();
        return a.exec();
    }
    
    K 1 Reply Last reply
    0
    • C Offline
      C Offline
      Charlie_Hdz
      wrote on last edited by
      #2

      There is not a conversion from "normal" C++ and "qt" C++.
      C++ is the same! You can compile pure C++ in Qt Creator without problems.
      Qt is an "extension" of C++.

      Kind Regards,
      Enrique Hernandez
      gearstech.com.mx
      chernandez@gearstech.com.mx

      ? 1 Reply Last reply
      1
      • C Charlie_Hdz

        There is not a conversion from "normal" C++ and "qt" C++.
        C++ is the same! You can compile pure C++ in Qt Creator without problems.
        Qt is an "extension" of C++.

        ? Offline
        ? Offline
        A Former User
        wrote on last edited by
        #3

        @Charlie_Hdz can you tell me how to add new code to existing?

        1 Reply Last reply
        0
        • C Offline
          C Offline
          Charlie_Hdz
          wrote on last edited by
          #4

          I'm afraid it is an imprecise request.

          Which compiler are you using?
          Which is your "existing" code?
          Which is your "new" code?

          To begin with...

          Kind Regards,
          Enrique Hernandez
          gearstech.com.mx
          chernandez@gearstech.com.mx

          ? 1 Reply Last reply
          0
          • C Charlie_Hdz

            I'm afraid it is an imprecise request.

            Which compiler are you using?
            Which is your "existing" code?
            Which is your "new" code?

            To begin with...

            ? Offline
            ? Offline
            A Former User
            wrote on last edited by
            #5

            @Charlie_Hdz encoder.h and encoder.cpp existing main.cpp new one using qt

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

              Hi,

              You should explain what exactly you want to do with your application. That will make things simpler to get help.

              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
              1
              • ? A Former User

                I have written a program in C++. I have tried that program in plain qt c++. That is working fine. Now I want to change my existing code. I am new for qt c++ I don't know how to add. I hope here I can get a solution.

                Existing Code: (Using wiringPi)

                Encoder Count.h

                #ifndef ENCODERCOUNT_H
                #define ENCODERCOUNT_H
                
                namespace Encoder {
                class EncoderCount;
                }
                
                class EncoderCount
                {
                public:
                    explicit EncoderCount();
                    ~EncoderCount();
                
                    static int cycleleftinterrupt;
                
                    int Left_Encoder_Read();
                
                    bool Encoder_Pulse();
                };
                
                #endif
                

                Encodercount.cpp

                #define ENCODER_LEFT 14
                
                int Flag_LeftInterrupt=0;
                
                bool ResetFalseLeft;
                
                using namespace std;
                
                EncoderCount::EncoderCount()
                {
                    pinMode(ENCODER_LEFT,INPUT);
                    digitalWrite(ENCODER_LEFT, HIGH);
                    ResetFalseLeft = false;
                }
                
                EncoderCount::~EncoderCount()
                {
                }
                
                 int EncoderCount::Left_Encoder_Read()
                {
                    return encoderValue/4;
                }
                
                 void leftencoderinterrupt(void)
                 {
                
                My stuff here............................
                
                encoderValue ++;
                     if(sum .............)
                 encoderValue --;
                
                     lastEncoded = encoded; 
                 }
                
                bool EncoderCount::Encoder_Pulse()
                {
                    if(wiringPiISR(ENCODER_LEFT,INT_EDGE_BOTH,&leftencoderinterrupt)<0)
                     {
                        return false;
                    }
                    return true;
                }
                

                I have tried the new code that is working fine that I want to take from project main and I will include here. I don't know how to add/include. I am new to c++, so please help to get a solution. Here I have attached new code

                #include <pigpio.h>
                #include "rotary_encoder.hpp"
                #include <iostream>
                #include <stdio.h>
                #include <unistd.h>
                
                #include <QApplication>
                
                void callback(int way)
                {
                   static int pos = 0;
                   pos += way;
                   std::cout << "pos=" << pos << std::endl;
                }
                
                int main(int argc, char *argv[])
                {
                    QApplication a(argc, argv);
                    Dialog w;
                    w.show();
                
                    if (gpioInitialise() < 0) return 1;
                    re_decoder dec(8, 11, callback);
                    sleep(50);
                    dec.re_cancel();
                    gpioTerminate();
                    return a.exec();
                }
                
                K Offline
                K Offline
                kenchan
                wrote on last edited by kenchan
                #7

                @Geeva As other people have said Qt is not a language it is a framework or library (which ever you prefer to call it).
                So, you have a header called Encoder Count.h, a cpp file called Encodercount.ccp (interesting inconsistency in the naming of the files). You have a main file which does not include the Encoder Count.h file? you do not include Encoder Count.h directly in the main file so we must assume you are including it in some other file which gets included?
                You are creating a dialog in your main function, so, are you having a problem with including a file in relation to the dialog implementation or what?
                You should probably show people here all of the code including the dialog to better explain the relationships and the exact issue you are having.

                1 Reply Last reply
                3
                • JerwinprabuJ Offline
                  JerwinprabuJ Offline
                  Jerwinprabu
                  wrote on last edited by
                  #8

                  As other people have said, Qt is an "extension" of C++. It is very simple, You can take from main.cpp to encoder.cpp. It looks like,

                  encoder.cpp

                  void leftencoder(int way)
                  {
                     static int pos = 0;
                     pos += way;
                     cout << "pos=" << pos << endl;
                     EncoderCount::cycleleftinterrupt = pos;
                  }
                  
                   void EncoderCount::Encoder_Pulse_pigpio()
                  {
                       cout << "pigpio ...test"<< endl;
                       if (gpioInitialise() < 0) return ;
                       re_decoder dec(11, 8, leftencoder);
                       sleep(50); // You can change sleep time (Based on your application)
                       dec.re_cancel();
                       gpioTerminate();
                  }
                  

                  Similar you can try for 2 or 3 encoders.

                  ? 1 Reply Last reply
                  1
                  • JerwinprabuJ Jerwinprabu

                    As other people have said, Qt is an "extension" of C++. It is very simple, You can take from main.cpp to encoder.cpp. It looks like,

                    encoder.cpp

                    void leftencoder(int way)
                    {
                       static int pos = 0;
                       pos += way;
                       cout << "pos=" << pos << endl;
                       EncoderCount::cycleleftinterrupt = pos;
                    }
                    
                     void EncoderCount::Encoder_Pulse_pigpio()
                    {
                         cout << "pigpio ...test"<< endl;
                         if (gpioInitialise() < 0) return ;
                         re_decoder dec(11, 8, leftencoder);
                         sleep(50); // You can change sleep time (Based on your application)
                         dec.re_cancel();
                         gpioTerminate();
                    }
                    

                    Similar you can try for 2 or 3 encoders.

                    ? Offline
                    ? Offline
                    A Former User
                    wrote on last edited by
                    #9

                    @Jerwinprabu Thank You. It is working fine now.

                    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