Results 1 to 17 of 17

Thread: Qt-like php

  1. #1
    Join Date
    Jan 2006
    Location
    Berlin, Germany
    Posts
    64
    Thanks
    1
    Thanked 4 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Cool Qt-like php

    Not sure if there are many people out there who program in both Qt and PHP but...

    This is not a formal announcement, (I just wanted to pre-announce this on here) but my company has been working on a framework for PHP that lets you create web applications with a qt-like syntax. Oh, also it uses ajax (if its available on the browser) to make the apps more desktop-like. (Everything (except certain signals) still works if the browser doesn't support ajax, it just has refreshes when you click something)

    this is a very simple code example:
    (I'm typing this on my Blackberry, so there may be a typo in the syntax lol)

    php Code:
    1. <?php
    2. require_once('QMainWindow.php');
    3. require_once('QApplication.php');
    4. require_once('QLabel.php');
    5. require_once('QPushButton.php');
    6.  
    7. class win extends QMainWindow {
    8.  
    9. protected $label;
    10. protected $button;
    11.  
    12. public function __construct(&$parent) {
    13. parent::__construct($parent);
    14.  
    15. $this->label = new QLabel('not clicked',$this);
    16. $this->button = new QPushButton('click me',$this);
    17.  
    18. connect($this->button,SIGNAL('clicked()'),$this,SLOT('changeLabel()'));
    19. connect($this,SIGNAL('updateText(QString)'),$this->label,SLOT('setText(QString)'));
    20.  
    21. }
    22.  
    23. public function changeLabel() {
    24. emit('updateText(clicked!)');
    25. }
    26.  
    27. }
    28.  
    29. $app = new QApplication;
    30. $w = new $win($app);
    31. $app->exec();
    32.  
    33. ?>
    To copy to clipboard, switch view to plain text mode 

    The above code does exactly what you would expect (and if your browser supports ajax, it does it without a browser refresh) (all of this outputs strict xhtml and standard javascript to the client browser)
    Our main goal is to follow the Qt 4.2 API as closely as possible (we already have a QCalendarWidget :-). ) considering that this is for a web browser. We already have reimplemented about 25% of the API and will likely have a beta release in about 6 months. Oh, and it also supports .ui designer files :-) and opperator overloading (if you have the PECL extension complied into php)
    One more thing to note, it REQUIRES php 5.2 (which isn't released yet either)(but this is the only server-side requirement) the only requirement on the client side is xhtml support, which even most cell phones have.

    :-)

    -Katrina
    Last edited by wysota; 19th July 2006 at 17:41. Reason: Added [highlight] tags

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Qt-like php

    Is there an online demo available somewhere?

  3. #3
    Join Date
    Jan 2006
    Posts
    75
    Thanks
    3
    Thanked 5 Times in 4 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Qt-like php

    Great, sounds like it can compare to the Google Web Toolkit:

    http://code.google.com/webtoolkit/

  4. #4
    Join Date
    Jan 2006
    Location
    Berlin, Germany
    Posts
    64
    Thanks
    1
    Thanked 4 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Qt-like php

    Quote Originally Posted by wysota
    Is there an online demo available somewhere?
    There should be in a couple days.

  5. #5
    Join Date
    Jan 2006
    Location
    Berlin, Germany
    Posts
    64
    Thanks
    1
    Thanked 4 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Wink Re: Qt-like php

    Quote Originally Posted by ball
    Great, sounds like it can compare to the Google Web Toolkit:

    http://code.google.com/webtoolkit/
    I'm sure GWT is great but I am reluctant to believe:

    Google Web Toolkit (GWT) is a Java software development framework that makes writing AJAX applications like Google Maps and Gmail easy for developers who don't speak browser quirks as a second language.

    When GMail doesn't work in Konqueror lol ;-)

  6. #6
    Join Date
    Jul 2006
    Posts
    79
    Thanks
    13
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qt-like php

    that sounds realy amazing..

    which licence will it be?
    the same dual licence system as in qt?

    regards..
    aman..

  7. #7
    Join Date
    Jan 2006
    Location
    Berlin, Germany
    Posts
    64
    Thanks
    1
    Thanked 4 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Thumbs up Re: Qt-like php

    Quote Originally Posted by aMan
    that sounds realy amazing..

    which licence will it be?
    the same dual licence system as in qt?

    regards..
    aman..
    Most likely, although this has yet to be determined. We have an agreement with a web site we are developing for not to release any of this code until the site launches (they want to be the first running on this framework) but after that we are free to do with it as we like. It will almost certainly be open-sourced in some way or another at that time.

  8. The following user says thank you to katrina for this useful post:

    aMan (19th July 2006)

  9. #8
    Join Date
    Jan 2006
    Location
    Berlin, Germany
    Posts
    64
    Thanks
    1
    Thanked 4 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Cool Re: Qt-like php

    Ok, we moved a server over to a cvs snapshot of PHP 5.2 up from 5.0 just to show you this, so you better like it ;-)

    By the way, the (currently un-official but likely will be offical) name for the framework is IQuiP

    disclaimers:
    this is a VERY simple demo that only uses a couple of basic widgets (we have more than this working already) and the program is meant to test basics of the signal/slot mechanism and is not an example of good application design. (yes, slots can be called directly like functions... they just aren't here)
    AJAX should automatically work if you have Javascript enabled (one current limitation... if you have javascript on but your browser doesnt support AJAX you will get an error... in this case you can turn javascript off for this site... currently the only browsers we have seen this on are really old ones and cell phones, but it should be fixed before release).
    If you have any trouble accessing this or getting it to work, please email me at kniolet@ildiinc.com and include browser version and (if possible) IP address at the time of the trouble. Any comments about speed,security,design,etc. are likely already being addressed so hold off on those until this is actually released, please.

    Also, the comments in the source were not intended for the people here LOL (but I left them in)
    Oh and the IQuiP framework and the sourcecode below are copyright (c) 2006 ILdI Inc.

    ok... here is the link:
    http://ildiinc.com/counter/index.php

    and the source:

    index.php
    php Code:
    1. <?php
    2. require("w.php");
    3. require("IQuiP/QApplication.php");
    4.  
    5. $app = new QApplication;
    6. if(!RESTORED) $window = new w($app); // if(!RESTORED) is currently needed when creating the main window... this should go away soon.
    7. $app->exec();
    8. ?>
    To copy to clipboard, switch view to plain text mode 

    w.php
    php Code:
    1. <?php
    2. include('IGPL/IQuiP/QMainWindow.php');
    3. include('IGPL/IQuiP/QPushButton.php');
    4. include('IGPL/IQuiP/QLabel.php');
    5.  
    6.  
    7. class w extends QMainWindow { // Creates the main applicatiton window
    8. private $numberLabel; // Initialize the number label
    9. private $count=0; // Initialize the counter to 0
    10. private $incrementButton; // Initialize the Increment button
    11. private $decrementButton; // Initialize the Decrement button
    12. private $colorButton; // Initialize button to change the color
    13. private $textColor;
    14.  
    15. public function __construct(&$parent=NULL) { // This block runs when the main window is created
    16. parent::__construct($parent); // Sets the parent of this object
    17. $this->setWindowTitle('A taste of IQuiP'); // Sets the title of this window
    18. $this->numberLabel = new QLabel($this->count,$this); // Creates the number label
    19. $this->incrementButton = new QPushButton('Increment',$this); // Creates the Increment button
    20. $this->decrementButton = new QPushButton('Decrement',$this); // Creates the Decrement button
    21. $this->colorButton = new QPushButton('Turn Text Red',$this); // Creates the blue button
    22. $this->textColor = 'black';
    23. $this->connect($this->incrementButton,'clicked()',$this,'increment()'); // What to do if Increment is clicked
    24. $this->connect($this->decrementButton,'clicked()',$this,'decrement()'); // What to do if Decrement is clicked
    25. $this->connect($this->colorButton,'clicked()',$this,'changeColor()');
    26. $this->connect($this,'updateNumber()',$this->numberLabel,'setText()');
    27. $this->connect($this,'updateButton()',$this->colorButton,'setText()');
    28. $this->connect($this,'updateColor()',$this->numberLabel,'setColor()');
    29. }
    30.  
    31. public function increment() { // This block runs when the user clicks Increment
    32. $this->count++; // Increment the counter by one
    33. $this->emit('updateNumber('.$this->count.')'); // Create an update signal
    34. }
    35.  
    36. public function decrement() { // This block runs when the user clicks Decrement
    37. $this->count--; // Decrement the counter by one
    38. $this->emit('updateNumber('.$this->count.')'); // Create an update signal
    39. }
    40.  
    41. public function changeColor() {
    42. switch($this->textColor) {
    43. case 'black':
    44. $this->emit('updateButton(Turn Text Blue)');
    45. $this->textColor='red';
    46. break;
    47. case 'red':
    48. $this->emit('updateButton(Turn Text Pink)');
    49. $this->textColor='blue';
    50. break;
    51. case 'blue':
    52. $this->emit('updateButton(Turn Text Purple)');
    53. $this->textColor='pink';
    54. break;
    55. case 'pink':
    56. $this->emit('updateButton(Turn Text Orange)');
    57. $this->textColor='purple';
    58. break;
    59. case 'purple':
    60. $this->emit('updateButton(Turn Text Black)');
    61. $this->textColor='orange';
    62. break;
    63. case 'orange':
    64. $this->emit('updateButton(Turn Text Red)');
    65. $this->textColor='black';
    66. break;
    67. }
    68. $this->emit("updateColor({$this->textColor})");
    69. }
    70. }
    71. ?>
    To copy to clipboard, switch view to plain text mode 
    Last edited by wysota; 21st July 2006 at 10:27. Reason: Changed [code] tags to [highlight=php]

  10. #9
    Join Date
    Jan 2006
    Location
    Berlin, Germany
    Posts
    64
    Thanks
    1
    Thanked 4 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Question Re: Qt-like php

    A couple things I know a couple people will be wondering about...

    tr() is implemented already (it just wasnt used in the above) plus it supports using an SQL database for the translations...

    SIGNAL() and SLOT() in connect() are supported to be more Qt-like, but are not required.
    same with the paremeters for the signal and the slot.

    As many things as possible act just like the Qt counterpart (but with PHP syntax) for instance...

    $label = new QLabel('text',$this);
    internally 'text' is converted to a QString instead of staying a PHP string

    or

    $bob = new QString("bob");
    $label->setText("hello ".$bob);
    this works

    QWidget's protected member $children is a QList instead of a PHP array

    obviously this requires more overhead than if we had used a regular PHP String and an array (although not as much as you might think)

    so, yeah, if anyone has any questions feel free to ask here or email me.

  11. #10
    Join Date
    Jul 2006
    Posts
    79
    Thanks
    13
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qt-like php

    first turn js off, click on a button (decrement for instance) and after the automatic reload reload the page a second time.

    the post messeges will be send a second time (i assume that) and the value will decrement a second time.

    it's not a bug, but a design problem i think. a user isn't expecting a change after he only reloads the window..


    but can you pleas give an example of model/view? or isn't it ready yet?

    regards..
    aman..

  12. #11
    Join Date
    Jan 2006
    Posts
    73
    Thanks
    16
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Qt-like php

    The object model, the language is still PHP; no way to have something like C++ instead?

  13. #12
    Join Date
    Jul 2006
    Posts
    79
    Thanks
    13
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qt-like php

    Quote Originally Posted by jcr
    The object model, the language is still PHP; no way to have something like C++ instead?
    i've never written something in php5, but i've read that they've extended the oop thing quite much.

    and no, there is no way to program php with cpp..

    you could use cgi bindings for cpp (nobody does that), but you won't be able to use this library..

    edit:
    nobody in the sense of nobody compared to the "millions" of using perl/cgi or php..

    regards..
    aman..
    Last edited by aMan; 22nd July 2006 at 01:10.

  14. #13
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qt-like php

    Quote Originally Posted by jcr
    no way to have something like C++ instead?
    There's Wt, which is quite similar to Qt.

  15. #14
    Join Date
    Jan 2006
    Location
    Berlin, Germany
    Posts
    64
    Thanks
    1
    Thanked 4 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Red face Re: Qt-like php

    Quote Originally Posted by aMan
    first turn js off, click on a button (decrement for instance) and after the automatic reload reload the page a second time.

    the post messeges will be send a second time (i assume that) and the value will decrement a second time.

    it's not a bug, but a design problem i think. a user isn't expecting a change after he only reloads the window..


    but can you pleas give an example of model/view? or isn't it ready yet?

    regards..
    aman..
    Yeah, this seems to be a browser quirk thing... We have seen that strange behavior in IE but it seems to work more naturally in Konqueror 3.5. (At least for us lol) thanks for the feedback though :-)

    Model/view is the big ugly beast we are in the process of tackling at the moment.

  16. #15
    Join Date
    Jan 2006
    Location
    Berlin, Germany
    Posts
    64
    Thanks
    1
    Thanked 4 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Talking Re: Qt-like php

    Quote Originally Posted by aMan
    i've never written something in php5, but i've read that they've extended the oop thing quite much.
    'Tis true! OOP has come a LOOONNGG way since php3! (And even since php4) it really has only been with the pre-release of 5.2 that we have been able to do some of the coding acrobatics needed to make this project possible. (Although php 5.1 came close)
    I, personally, had wanted to make something like this since I started using PHP a few years ago and really missed the convienience of signals and slots and hated that programming in php meant programming in php, javascript, html, and sql and not simply programming in php. So it is very exiting for me that we will soon have this done :-D

  17. #16
    Join Date
    Jul 2006
    Posts
    79
    Thanks
    13
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qt-like php

    Quote Originally Posted by katrina
    ...We have seen that strange behavior in IE but it seems to work more naturally in Konqueror 3.5. ...
    i'm using opera 9..
    hm.. the dialog "would you like to send post data again.." is ugly too (in konq 3.4 and firefox) in my opinion..

    maybe an intermediate page or something would help, but that would slow down the response speed of the app very much.

    Model/view is the big ugly beast we are in the process of tackling at the moment.
    thanks for the answer..

  18. #17
    Join Date
    Jan 2006
    Location
    Berlin, Germany
    Posts
    64
    Thanks
    1
    Thanked 4 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Red face Re: Qt-like php

    Quote Originally Posted by aMan
    i'm using opera 9..
    hm.. the dialog "would you like to send post data again.." is ugly too (in konq 3.4 and firefox) in my opinion..

    maybe an intermediate page or something would help, but that would slow down the response speed of the app very much.


    thanks for the answer..
    Thanks for the feedback :-)

    Some of those things are just the downsides of making "applications" that run in browsers. Since browsers were designed for static pages they tend to have trouble dealing with forward/backward/reload when the pages are very not static. The "would you like to resend post data" is from the browser and there isn't a real way to stop it (because we pretty much have to use post data and there is no standard way to disable a browser from showing this)
    We will likely be implimenting some form of the new undo/redo classes to deal with these a little better. Fwiw, the software that my bank uses shows the same problems with forward/back/reload except theirs cannot recover at all (you have to log out and back in if you hit the back button) and they probably paid millions for that software LOL

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.