Forum > QT

libqt6pas and ChatGPT

(1/3) > >>

Bogen85:
libqt6pas is working great on Linux.

I can even get ChatGPT to write simple gui apps for free pascal using it, and some of them compile and run as is without modification.

I say "some" because each time you ask it might produce different code, which does not always compile or work.


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---I need a Qt6 graphical hello world in free pascal.Requirements:- It will use the qt6 unit- The qt6 unit is described here: https://raw.githubusercontent.com/davidbannon/libqt6pas/master/cbindings/qt62.pas- All literal strings must be explicity declared as WideString variables.- Declared variable names must be prefixed with _- Address of WideString variables must be used in function calls.- Everything created must be destroyed.- Constants must be declared before they are used before variables.- QApplication_exec does not take an argument.- Needs objfpc directive. 
Which produces this:


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---program HelloWorld; {$mode objfpc}{$H+} uses  qt6; var  _app : QApplicationH;  _window : QWidgetH;  _helloWorld : WideString; begin  _helloWorld := 'Hello World!';  _app := QApplication_create(@argc, @argv);  _window := QWidget_create();  QWidget_setWindowTitle(_window, @_helloWorld);  QWidget_show(_window);  QApplication_exec();  QWidget_destroy(_window);  QApplication_destroy(_app);end. 
Which compiles and runs...

It does not understand how to do event handlers correctly, but it makes an attempt when you say things like this:


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---I need a Qt6 graphical hello world in free pascal.Requirements:- It will use the qt6 unit- The qt6 unit is described here: https://raw.githubusercontent.com/davidbannon/libqt6pas/master/cbindings/qt62.pas- All literal strings must be explicity declared as WideString variables.- A text edit will be created in the main window.- A procedure named 'what' that prints 'how' will be created.- When a key is pressed in the text edit the procedure 'what' will be called.- Declared variable names must be prefixed with _- Address of WideString variables must be used in function calls.- Everything created must be destroyed.- Constants must be declared before they are used before variables.- QApplication_exec does not take an argument.- Needs objfpc directive. 
So ChatGPT can't really handle event handlers or filters correctly for libqt6pas.

Those are not hard to do in Free Pascal with libqt6pas using QAbstractButton_hook_hook_*  QObject_hook_hook_events and the like though.
"teaching" ChatGPT to do those things correctly would take some patience...

But any ways, ChatGPT can do some simple things with free pascal and libqt6pas.

Here is the funny thing though, if you make the following request, it produces code that won't work.



--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---// @2023-01-06 14:25:27 CST [Sent]// Show me a graphical hello world using Free Pascal and qt6.// @2023-01-06 14:25:34 CST [Received]// This example uses the qt6 library to create a graphical hello world program using Free Pascal.program HelloWorld; {$mode objfpc}{$H+} uses  qtwidgets, qtobjects, qtgui; var  Wnd: QWidgetH;  Btn: QPushButtonH; begin  Wnd := QWidget_Create(nil);  try    QWidget_SetWindowTitle(Wnd, 'Hello World');    Btn := QPushButton_Create(Wnd);    try      QPushButton_SetText(Btn, 'Hello World');      QWidget_SetGeometry(Btn, 10, 10, 100, 30);      QWidget_Show(Btn);    finally      QWidget_Destroy(Btn);    end;    QApplication_Exec;  finally    QWidget_Destroy(Wnd);  end;end. 

Bogen85:
I had to say this:

--- Quote --- Declared variable names must be prefixed with _
--- End quote ---

Because Chat GPT was creating variable names that are free pascal keywords.

Thaddy:
You can add  ". Variable names must not be type names or keywords." to the request.
I ran into the same issue.

Bogen85:
As far as ChatGPT's ability to read current websites...


--- Quote ---Requirements:
- It will use the qt6 unit
- The qt6 unit is described here: https://raw.githubusercontent.com/davidbannon/libqt6pas/master/cbindings/
qt62.pas
--- End quote ---

Even when this I have doubts about that actually understands or has read anything from there.
It appears to have done so, because without using that, the results are incorrect.

However, it will often provide code that refers to things not part of the binding. They look syntactically correct and are referring to things part of q6, but they binding does not have them.

So, I'm not 100% what it is doing. It may possible it assimilated libqt5pas related material from 2019 and prior.

The "success" I've had getting GPT text davinci 3 to use updated material has been spotty at best. And when it has appeared to work, I'm just not completely sure if it was indeed reading the new material.

For documentation pages intended for human, yes. For actual code, no.

 

PierceNg:
Having seen a few programs written by this AI, is there anything particularly standing out to you with regards to its code formatting style?

For Pascal especially for if-then-begin-end-else-begin-end human programmers have all kinds of styles. Does this bot look like it has one consistent style or more like it switches between different styles (presumably based on what source material it is recalling)? 

Navigation

[0] Message Index

[#] Next page

Go to full version