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. API Implementation from Existing GUI Qt Application.

API Implementation from Existing GUI Qt Application.

Scheduled Pinned Locked Moved Unsolved General and Desktop
15 Posts 3 Posters 1.6k 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.
  • S Offline
    S Offline
    shivaVMC
    wrote on last edited by aha_1980
    #1

    Hi Team,
    I have ported Qt application from Win-Linux.
    Now I m planning for API implementation for the same.
    Thing is I m using 2 fields like
    Motor1: A text box here which is editable
    Motor2: A text box here which is editable
    Values for motor rotation (30,60,90,180 degree)I m entering from GUI.

    Now,In same way I want to do it from command line to rotate Motor1 and Motor2
    Like,
    ./Motor 30 60 (It should rotate as per mentioned value)
    ./Motor 30
    ./Motor 0 60

    Can I get a support on doing this API.

    S 1 Reply Last reply
    0
    • S shivaVMC

      Hi Team,
      I have ported Qt application from Win-Linux.
      Now I m planning for API implementation for the same.
      Thing is I m using 2 fields like
      Motor1: A text box here which is editable
      Motor2: A text box here which is editable
      Values for motor rotation (30,60,90,180 degree)I m entering from GUI.

      Now,In same way I want to do it from command line to rotate Motor1 and Motor2
      Like,
      ./Motor 30 60 (It should rotate as per mentioned value)
      ./Motor 30
      ./Motor 0 60

      Can I get a support on doing this API.

      S Offline
      S Offline
      shivaVMC
      wrote on last edited by shivaVMC
      #2

      @shivaVMC
      lnEd_Mot1 = new QLineEdit(gBxSendSettings);
      lnEd_Mot1->setObjectName(QStringLiteral("lnEd_Mot1"));

      lnEd_Mot1->setInputMethodHints(Qt::ImhDigitsOnly|Qt::ImhFormattedNumbersOnly);
      verticalLayout_2->addWidget(lnEd_Mot1);

          lnEd_Mot2 = new QLineEdit(gBxSendSettings);
          lnEd_Mot2->setObjectName(QStringLiteral("lnEd_Mot2"));
          lnEd_Mot2->setInputMethodHints(Qt::ImhDigitsOnly);
          verticalLayout_2->addWidget(lnEd_Mot2);
      

      The above lines are now existing code,what should be the changes in this to make its a command line

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

        Hi,

        Use QCommandLineParser to get the parameters from the command line and pass them to the objects controlling the motors.

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        S 1 Reply Last reply
        3
        • SGaistS SGaist

          Hi,

          Use QCommandLineParser to get the parameters from the command line and pass them to the objects controlling the motors.

          S Offline
          S Offline
          shivaVMC
          wrote on last edited by
          #4

          @SGaist
          Hi SGaist
          int main(int argc, char *argv[])
          {
          int f1,f2;
          QApplication a(argc, argv);
          QCommandLineParser parser;
          QCommandLineOption CmndlnOption (QStringList () << "f" <<"target-directory", QCoreApplication::translate ("main","Copy all source files into <directory>."),QCoreApplication::translate ("main", "directory"));
          parser.addOption (CmndlnOption);
          parser.process (a);

          QStringList args = a.arguments(); //1
          //QStringList args = parser.positionalArguments();
          qDebug() << "Args1 --->"<<args.at(1)<<"Args2 --->"<< args.at(2);
          M1=args.at(1).toInt(); //2
          M2=args.at(2).toInt(); //3
          qDebug() << "M1=======\n"<<M1<< "M2=======\n" <<M2;
          Mot_1_2(M1,M2);
          qDebug () << parser.values (CmndlnOption);
          return a.exec();
          }

          }

          int Motor_1_2(int mtr1,int mtr2)
          {
          //Some action is taken here,its too lenghty code

          }

          I m facing Segmentation fault in QString::operator=(QString const&) ()
          what could be the fix ? can you please suggest on this

          Something wrong in these 3 lines can you please suggest on this lines,as I want to collect the commandline values saparetly in each different variable and want to perform some validation in Motor_1_2() function.
          QStringList args = a.arguments(); //1
          M1=args.at(1).toInt(); //2
          M2=args.at(2).toInt(); //3
          when I comment above three lines it looks fine.

          jsulmJ 1 Reply Last reply
          0
          • S shivaVMC

            @SGaist
            Hi SGaist
            int main(int argc, char *argv[])
            {
            int f1,f2;
            QApplication a(argc, argv);
            QCommandLineParser parser;
            QCommandLineOption CmndlnOption (QStringList () << "f" <<"target-directory", QCoreApplication::translate ("main","Copy all source files into <directory>."),QCoreApplication::translate ("main", "directory"));
            parser.addOption (CmndlnOption);
            parser.process (a);

            QStringList args = a.arguments(); //1
            //QStringList args = parser.positionalArguments();
            qDebug() << "Args1 --->"<<args.at(1)<<"Args2 --->"<< args.at(2);
            M1=args.at(1).toInt(); //2
            M2=args.at(2).toInt(); //3
            qDebug() << "M1=======\n"<<M1<< "M2=======\n" <<M2;
            Mot_1_2(M1,M2);
            qDebug () << parser.values (CmndlnOption);
            return a.exec();
            }

            }

            int Motor_1_2(int mtr1,int mtr2)
            {
            //Some action is taken here,its too lenghty code

            }

            I m facing Segmentation fault in QString::operator=(QString const&) ()
            what could be the fix ? can you please suggest on this

            Something wrong in these 3 lines can you please suggest on this lines,as I want to collect the commandline values saparetly in each different variable and want to perform some validation in Motor_1_2() function.
            QStringList args = a.arguments(); //1
            M1=args.at(1).toInt(); //2
            M2=args.at(2).toInt(); //3
            when I comment above three lines it looks fine.

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

            @shivaVMC said in API Implementation from Existing GUI Qt Application.:

            QStringList args = a.arguments(); //1
            M1=args.at(1).toInt(); //2
            M2=args.at(2).toInt(); //3

            You don't check how many parameters you got! This are basics.
            So, M1=args.at(1).toInt(); could be out of range.

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

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

              In addition to what @jsulm wrote, you should take a look at the documentation of QCommandLineParser. There is shown how to properly check for the availability of an option.

              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
              • S Offline
                S Offline
                shivaVMC
                wrote on last edited by shivaVMC
                #7

                Hi Team,
                I m plannig to implement API for the exixting code as mentioned in the begininng of the topic.
                Instead of entering the values from GUI,I want to make the API for the motor function and want to pass the values to that API.The reason to make the API are I want to use these API's in another application where I wanat to calll this API by passing the M1 and M2 values.
                Please any suggestion on this.

                Now I m planning for API implementation for the same.
                Thing is I m using 2 fields like
                Motor1: A text box here which is editable
                Motor2: A text box here which is editable
                Values for motor rotation (30,60,90,180 degree)I m entering from GUI.

                Now,In same way I want to do it through API to rotate Motor1 and Motor2
                Like,
                ./Motor 30 60 (It should rotate as per mentioned value)
                ./Motor 30
                ./Motor 0 60

                Can I get a support on doing this API.

                jsulmJ 1 Reply Last reply
                0
                • S shivaVMC

                  Hi Team,
                  I m plannig to implement API for the exixting code as mentioned in the begininng of the topic.
                  Instead of entering the values from GUI,I want to make the API for the motor function and want to pass the values to that API.The reason to make the API are I want to use these API's in another application where I wanat to calll this API by passing the M1 and M2 values.
                  Please any suggestion on this.

                  Now I m planning for API implementation for the same.
                  Thing is I m using 2 fields like
                  Motor1: A text box here which is editable
                  Motor2: A text box here which is editable
                  Values for motor rotation (30,60,90,180 degree)I m entering from GUI.

                  Now,In same way I want to do it through API to rotate Motor1 and Motor2
                  Like,
                  ./Motor 30 60 (It should rotate as per mentioned value)
                  ./Motor 30
                  ./Motor 0 60

                  Can I get a support on doing this API.

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

                  @shivaVMC What exactly is your question now?
                  You need a function with following parameters (if I understood your description correctly):

                  • Motor to use (should be enum)
                  • Rotation (it looks like you have fix degrees for rotation in this case you can use enum as well)
                  enum class Motor
                  {
                      Motor_1,
                      Motor_2
                  };
                  enum class Rotation
                  {
                      Rotate_30,
                      Rotate_60,
                      Rotate_90,
                      Rotate_180
                  };
                  void rotate(Motor motor, Rotation rotation);
                  

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

                  S 1 Reply Last reply
                  1
                  • jsulmJ jsulm

                    @shivaVMC What exactly is your question now?
                    You need a function with following parameters (if I understood your description correctly):

                    • Motor to use (should be enum)
                    • Rotation (it looks like you have fix degrees for rotation in this case you can use enum as well)
                    enum class Motor
                    {
                        Motor_1,
                        Motor_2
                    };
                    enum class Rotation
                    {
                        Rotate_30,
                        Rotate_60,
                        Rotate_90,
                        Rotate_180
                    };
                    void rotate(Motor motor, Rotation rotation);
                    
                    S Offline
                    S Offline
                    shivaVMC
                    wrote on last edited by
                    #9

                    @jsulm
                    Exactly,perfect understanding of my problem.
                    Now I want to remove the GUI option for entering the values from GUI,how can I disable that option ?

                    jsulmJ 1 Reply Last reply
                    0
                    • S shivaVMC

                      @jsulm
                      Exactly,perfect understanding of my problem.
                      Now I want to remove the GUI option for entering the values from GUI,how can I disable that option ?

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

                      @shivaVMC I don't understand: in the code I posted there is nothing at all related to any GUI. What do you want to remove?

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

                      S 1 Reply Last reply
                      0
                      • jsulmJ jsulm

                        @shivaVMC I don't understand: in the code I posted there is nothing at all related to any GUI. What do you want to remove?

                        S Offline
                        S Offline
                        shivaVMC
                        wrote on last edited by shivaVMC
                        #11

                        @jsulm
                        I want to disable from my application,any option to disable?becasue I want to test this application through another application just by calling this api as ./motor M1,30

                        jsulmJ 1 Reply Last reply
                        0
                        • S shivaVMC

                          @jsulm
                          I want to disable from my application,any option to disable?becasue I want to test this application through another application just by calling this api as ./motor M1,30

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

                          @shivaVMC The I would say your API should be a shared library which you can use in any other project. See http://doc.qt.io/qt-5/sharedlibrary.html

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

                          S 2 Replies Last reply
                          3
                          • jsulmJ jsulm

                            @shivaVMC The I would say your API should be a shared library which you can use in any other project. See http://doc.qt.io/qt-5/sharedlibrary.html

                            S Offline
                            S Offline
                            shivaVMC
                            wrote on last edited by
                            #13

                            @jsulm
                            Yeah,Exactly right
                            I will check the link and try to create a shared lib.Get back you soon for the doubts if any .

                            :)
                            :)

                            1 Reply Last reply
                            0
                            • jsulmJ jsulm

                              @shivaVMC The I would say your API should be a shared library which you can use in any other project. See http://doc.qt.io/qt-5/sharedlibrary.html

                              S Offline
                              S Offline
                              shivaVMC
                              wrote on last edited by
                              #14

                              @jsulm
                              Hi :)
                              I have implemented the library in Qt and have called in C language.
                              facing with the error as,

                              fatal error: QtCore/qglobal.h: No such file or directory
                              #include <QtCore/qglobal.h>

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

                                You're likely missing the include path to Qt's includes.

                                How are you building that C project ?

                                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

                                • Login

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