API Implementation from Existing GUI Qt Application.
-
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 60Can I get a support on doing this API.
-
@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
-
Hi,
Use QCommandLineParser to get the parameters from the command line and pass them to the objects controlling the motors.
-
@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 thisSomething 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. -
@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(); //3You don't check how many parameters you got! This are basics.
So, M1=args.at(1).toInt(); could be out of range. -
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.
-
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 60Can I get a support on doing this API.
-
@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);
-
@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
-
You're likely missing the include path to Qt's includes.
How are you building that C project ?