Recent

Author Topic: libqt6pas and ChatGPT  (Read 1925 times)

Bogen85

  • Hero Member
  • *****
  • Posts: 595
libqt6pas and ChatGPT
« on: January 06, 2023, 09:29:24 pm »
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  [Select][+][-]
  1. I need a Qt6 graphical hello world in free pascal.
  2. Requirements:
  3. - It will use the qt6 unit
  4. - The qt6 unit is described here: https://raw.githubusercontent.com/davidbannon/libqt6pas/master/cbindings/
  5. qt62.pas
  6. - All literal strings must be explicity declared as WideString variables.
  7. - Declared variable names must be prefixed with _
  8. - Address of WideString variables must be used in function calls.
  9. - Everything created must be destroyed.
  10. - Constants must be declared before they are used before variables.
  11. - QApplication_exec does not take an argument.
  12. - Needs objfpc directive.
  13.  

Which produces this:

Code: Pascal  [Select][+][-]
  1. program HelloWorld;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. uses
  6.   qt6;
  7.  
  8. var
  9.   _app : QApplicationH;
  10.   _window : QWidgetH;
  11.   _helloWorld : WideString;
  12.  
  13. begin
  14.   _helloWorld := 'Hello World!';
  15.   _app := QApplication_create(@argc, @argv);
  16.   _window := QWidget_create();
  17.   QWidget_setWindowTitle(_window, @_helloWorld);
  18.   QWidget_show(_window);
  19.   QApplication_exec();
  20.   QWidget_destroy(_window);
  21.   QApplication_destroy(_app);
  22. end.
  23.  

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  [Select][+][-]
  1. I need a Qt6 graphical hello world in free pascal.
  2. Requirements:
  3. - It will use the qt6 unit
  4. - The qt6 unit is described here: https://raw.githubusercontent.com/davidbannon/libqt6pas/master/cbindings/
  5. qt62.pas
  6. - All literal strings must be explicity declared as WideString variables.
  7. - A text edit will be created in the main window.
  8. - A procedure named 'what' that prints 'how' will be created.
  9. - When a key is pressed in the text edit the procedure 'what' will be called.
  10. - Declared variable names must be prefixed with _
  11. - Address of WideString variables must be used in function calls.
  12. - Everything created must be destroyed.
  13. - Constants must be declared before they are used before variables.
  14. - QApplication_exec does not take an argument.
  15. - Needs objfpc directive.
  16.  

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  [Select][+][-]
  1. // @2023-01-06 14:25:27 CST [Sent]
  2. // Show me a graphical hello world using Free Pascal and qt6.
  3. // @2023-01-06 14:25:34 CST [Received]
  4. // This example uses the qt6 library to create a graphical hello world program using Free Pascal.
  5. program HelloWorld;
  6.  
  7. {$mode objfpc}{$H+}
  8.  
  9. uses
  10.   qtwidgets, qtobjects, qtgui;
  11.  
  12. var
  13.   Wnd: QWidgetH;
  14.   Btn: QPushButtonH;
  15.  
  16. begin
  17.   Wnd := QWidget_Create(nil);
  18.   try
  19.     QWidget_SetWindowTitle(Wnd, 'Hello World');
  20.     Btn := QPushButton_Create(Wnd);
  21.     try
  22.       QPushButton_SetText(Btn, 'Hello World');
  23.       QWidget_SetGeometry(Btn, 10, 10, 100, 30);
  24.       QWidget_Show(Btn);
  25.     finally
  26.       QWidget_Destroy(Btn);
  27.     end;
  28.     QApplication_Exec;
  29.   finally
  30.     QWidget_Destroy(Wnd);
  31.   end;
  32. end.
  33.  
« Last Edit: January 07, 2023, 02:32:53 am by Bogen85 »

Bogen85

  • Hero Member
  • *****
  • Posts: 595
Re: libqt6pas and ChatGPT
« Reply #1 on: January 06, 2023, 09:31:17 pm »
I had to say this:
Quote
Declared variable names must be prefixed with _

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

Thaddy

  • Hero Member
  • *****
  • Posts: 14205
  • Probably until I exterminate Putin.
Re: libqt6pas and ChatGPT
« Reply #2 on: January 07, 2023, 06:30:23 am »
You can add  ". Variable names must not be type names or keywords." to the request.
I ran into the same issue.
« Last Edit: January 07, 2023, 07:14:37 am by Thaddy »
Specialize a type, not a var.

Bogen85

  • Hero Member
  • *****
  • Posts: 595
Re: libqt6pas and ChatGPT
« Reply #3 on: January 16, 2023, 02:56:10 am »
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

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.

 
« Last Edit: January 16, 2023, 03:56:13 am by Bogen85 »

PierceNg

  • Sr. Member
  • ****
  • Posts: 369
    • SamadhiWeb
Re: libqt6pas and ChatGPT
« Reply #4 on: January 16, 2023, 03:35:55 am »
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)? 

Bogen85

  • Hero Member
  • *****
  • Posts: 595
Re: libqt6pas and ChatGPT
« Reply #5 on: January 16, 2023, 03:54:21 am »
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)?

From what I've see it appears to be consistent as to style, when the code is correct. I have seen that often leaves out (not every time though) the begin..end around a multi line if block that is followed by an else.

It somehow sometimes thinks that everything between the then and the else is part of the then.

I've not actually paid much attention there. Anything I consider useful I run though JCF.

But useful is not easy....anything trivial, no point in asking for it from an AI.

Anything complex I see most as an idea about how to approach it, and so far the few things it has made for me that were correct or close to being correct I completely refactored into something I could actually use and maintain.


zeljko

  • Hero Member
  • *****
  • Posts: 1594
    • http://wiki.lazarus.freepascal.org/User:Zeljan
Re: libqt6pas and ChatGPT
« Reply #6 on: January 16, 2023, 08:45:03 am »
I've tested few weeks ago for events: Write event for textChanged hook

MarkMLl

  • Hero Member
  • *****
  • Posts: 6676
Re: libqt6pas and ChatGPT
« Reply #7 on: January 16, 2023, 11:36:54 am »
From what I've see it appears to be consistent as to style, when the code is correct. I have seen that often leaves out (not every time though) the begin..end around a multi line if block that is followed by an else.

It somehow sometimes thinks that everything between the then and the else is part of the then.

...which is the style adopted by later Wirth languages (Modula-2 and onwards), Ada, ALGOL-68, VHDL etc. as opposed to Pascal, C, ALGOL-W and older. I think that illustrates an interesting limitation to its "understanding" of what's being asked: why is it favouring the less-popular languages (Ada etc.) at the expense of the most popular (Pascal) which almost certainly has the most code examples floating around?

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

 

TinyPortal © 2005-2018