QT C++ code samples

More
7 years 4 months ago - 7 years 4 months ago #136306 by Grotius
QT C++ code samples was created by Grotius
Why post something about QT C++?

QT C++ is a nice option if we want to make a stand alone program, that could be anything up to Linuxcnc.

In my case like a dxf2gcode program or a parametric g-code generator program with a dynamic visual product output.

I started in GTK+ almost 3 year's ago with python only for linuxcnc gui's, later on i started project's in C for writing linuxcnc components. Some time ago i switched to QT C++ because i was lost to achieve a stable GTK+ OpenGL solution.
At the moment i am learning C++. The benefit of C++ is that it can be used in combination with C. My goal is to provide some basic examples in this topic over time. I hope the non experienced C++ user's like me can find out how the provided code is working.

Attached is a basic simple QT project example how to use local and global variables within a user gui.
Why is this code important? It's a building block to make parametric user input's for a g-code generator possible.

You can open the project by loading the .pro file.
To execute the already compiled program, unzip untitled1 and type in terminal : ./untitled1

If their are experienced QT user's. I am looking for very basic OpenGL examples how to draw lines etc. Don't hesitate to provide a example over here.

Picture of program gui :


The attached video is what i want to learn coming time, we can use this with QT C++, very cool !!
Attachments:
Last edit: 7 years 4 months ago by Grotius.
The following user(s) said Thank You: phillc54, tommylight

Please Log in or Create an account to join the conversation.

More
7 years 4 months ago #136355 by pl7i92
Replied by pl7i92 on topic QT C++ code samples
very nice
i think that is well over the top of many machine users
that just want to have a user button to there machine
you as a machine builder are sure the target users
and your customers will pay for it to add this button to your system

Please Log in or Create an account to join the conversation.

More
7 years 4 months ago - 7 years 4 months ago #136397 by Grotius
Replied by Grotius on topic QT C++ code samples
Attached a code example for drawing a line with the QT C++ OpenGLWidget.

This is the first example that lives on the internet which can draw a line with the new OpenGLWidget trough a
input field and execute button. I am proud to provide this bare basic code example on this forum !
It will be looked and downloaded by many people all over the world over the coming years. I think programming student's are
very happy with this code example. It's a nice start.

The example is clean written so user's can verify the code quite easy.

1. You can insert a value in the gui input text box. This value is limited to float value's with 2 decimal's accuracy.
2. The value of the input box is passed trough a extern variable to a different C++ file that does the OpenGL code.
3. The button passes the new value into the variable.
4. Screen is updated with timer function.
5. Provided is a basic zoom in and zoom out function that can be connected to the gui.
6. The file's are commented.
7. This example can be expanded to a g-code generator or a cad program.
8. A picture resource file example is provided.
9. Do not use a extern variable name like x for testing. This x is already used in OpenGL code, the error it will give will result in scratching your head a few hours. Use a name like xx or xvalue instead.
10. The application has a console output.
11. The code is working with latest QT release 5.12.3

Screen shot of the program output :


The QT C++ project files are attached. To open the project in QT select the .pro file.
To install QT, visit : www.qt.io/download

To try the already compiled program, unzip the untitled.zip file and type in terminal : ./untitled

@Maximilian,

I have to think about your suggestion "over the top". ;)
Attachments:
Last edit: 7 years 4 months ago by Grotius.
The following user(s) said Thank You: tommylight

Please Log in or Create an account to join the conversation.

More
7 years 4 months ago - 7 years 4 months ago #136399 by BigJohnT
Replied by BigJohnT on topic QT C++ code samples
While possibly over the top of machine users, on the other hand it's right in line for machine builders who know a bit of code.

I should do a project in C++ soon, just finished one in C and program in Python all the time.

JT
Last edit: 7 years 4 months ago by BigJohnT.
The following user(s) said Thank You: Grotius

Please Log in or Create an account to join the conversation.

More
7 years 4 months ago - 7 years 4 months ago #136401 by Grotius
Replied by Grotius on topic QT C++ code samples
@John Thornton,

Which C++ project are you interested in to make?

I have a question for you about coding.

If we have a dxf cad file sorted out for example in c, we can display both attached object's directly into a c coded g-code viewer, like a modified program example as above that works with c array's.

Only issue is, the dxf cad file output has no logic about :

G41 <D-> (left of programmed path)
G42 <D-> (right of programmed path)

So the cad file sometimes take's the path of G41 and sometimes takes the pat'h of G42.
There is no logic in that so far as i can see in the cad output. So it's a guess that has to be solved. Making a program that
works with G41 and G42 is in my perspective the future for Linuxcnc. Microstep machine's are also working this way.

So i made a if/else c code to look if the path is G41 or if the path is G42.
But in the most right picture, my logic is working in about 90% of the times. Does the logic takes a 1000 lines of code to keep up at 100% succes rate?



How can we solve this bottleneck easy?

Maybe you have a idea i overlooked so far.
Last edit: 7 years 4 months ago by Grotius.

Please Log in or Create an account to join the conversation.

More
7 years 4 months ago #136413 by BigJohnT
Replied by BigJohnT on topic QT C++ code samples
How do you determine the direction now?

Just off the top of my head you need to know what side of the path the user wants to cut ie which side is a part and which side is scrap. So that takes user input.

Next if it is a milling application you need to know the direction ie climb or conventional cut, for plasma it usually doesn't matter much.

Yea DXF files can be a mess I wrote a golang tool to import a DXF and starting with the first element it found spit out G code. I was impressed with the speed but dislike the language restrictions about files and such.

Not sure what I want to do in C++ I need to finish up my 7i92 configuration tool first so I'll have all the Mesa Ethernet cards with a simple configuration tool. I know pnccnof does some amazing things but I feel that it is to intimidating for fresh users.

JT

Please Log in or Create an account to join the conversation.

Time to create page: 0.597 seconds
Powered by Kunena Forum