How to access ui form widgets

64 views
Skip to first unread message

apolinar

unread,
Mar 17, 2011, 4:36:42 PM3/17/11
to Harbour Users
#include "hbqtgui.ch"
PROCEDURE Main()
LOCAL application,window,ui,file
application := QApplication()
file := QFile("sample.ui")
file:open(1)
ui := QUiLoader()
window := ui:load(file)
file:close()
window:show()
application:exec()
application:quit()
RETURN

this is sample 033-QUiLoader.prg by Giovani
Can someone show me how to acces widgets on sample.ui
window:pushButton:connect( "clicked()", {|| ... } ) does not work

2) I would like to see sample how to load sample.ui if sample.ui is
linked
in hbp

Thanks, Apolinar

Pritpal Bedi

unread,
Mar 17, 2011, 11:56:13 PM3/17/11
to Harbour Users
> window:pushButton:connect( "clicked()", {|| ... } ) does not work

window:q_pushButton:connect( "clicked()", {|| ... } )

> 2) I would like to see sample how to load sample.ui if  sample.ui is
> linked in hbp

Examine hbIDE sources.

Pritpal Bedi

calimero22

unread,
Mar 18, 2011, 5:20:27 AM3/18/11
to Harbour Users
Hi
The window is shown BUT my button does'nt respond. My source is this:
Regards
Giovanni


#include "hbqtgui.ch"
PROCEDURE Main()
LOCAL application,window,ui,file
application := QApplication()
file := QFile("sample.ui")
file:open(1)
ui := QUiLoader()
window := ui:load(file)
file:close()
window:q_pushButton:connect( "clicked()", { | |
window:move(100,100) } )
window:show()
application:exec()
application:quit()
RETURN


The UI file (sample.ui) is the following:


<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MainWindow</class>
<widget class="QMainWindow" name="MainWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>255</width>
<height>215</height>
</rect>
</property>
<property name="windowTitle">
<string>MainWindow</string>
</property>
<widget class="QWidget" name="centralwidget">
<widget class="QPushButton" name="pushButton">
<property name="geometry">
<rect>
<x>80</x>
<y>70</y>
<width>75</width>
<height>23</height>
</rect>
</property>
<property name="text">
<string>PushButton</string>
</property>
</widget>
</widget>
<widget class="QMenuBar" name="menubar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>255</width>
<height>20</height>
</rect>
</property>
</widget>
<widget class="QStatusBar" name="statusbar"/>
</widget>
<resources/>
<connections/>
</ui>

Pritpal Bedi

unread,
Mar 18, 2011, 2:24:07 PM3/18/11
to Harbour Users
Hi

> The window is shown BUT my button does'nt respond. My source is this:

Instead of .ui, include it in .hbp and use
that interface. Via .ui you cannot connect events
to its child objects.

As per your example:

.hbp
===

yourprg.prg
sample.ui

Then in your yourprg you will do this:

oUI := hbqtui_sample( q_any_parent_is_you_provide_which_can_be_nil )
^^^^^^^ Appended by hbmk2
^^^^^^^^ .ui filename as postfix

oUI:q_pushButton:connect( ... )

Let me know if it solved your issue.

BTW do not use .ui files directly. It will increase the
load size of your application by wooping 23+ MB.

Pritpal Bedi

Pritpal Bedi

unread,
Mar 18, 2011, 2:26:32 PM3/18/11
to Harbour Users
Hi


> BTW do not use .ui files directly. It will increase the
> load size of your application by wooping 23+ MB.

Also you will not be shipping .ui with your application,
one less factor to worry about.

Pritpal Bedi

apolinar

unread,
Mar 18, 2011, 4:06:15 PM3/18/11
to Harbour Users

>
> .hbp
> ===
>
> yourprg.prg
> sample.ui
>
> Then in your yourprg you will do this:
>
> oUI := hbqtui_sample( q_any_parent_is_you_provide_which_can_be_nil )
>          ^^^^^^^                      Appended by hbmk2
>                      ^^^^^^^^        .ui filename as postfix
>
> oUI:q_pushButton:connect( ... )
>
> Let me know if it solved your issue.
>
> BTW do not use .ui files directly. It will increase the
> load size of your application by wooping 23+ MB.
>
> Pritpal Bedi

thank you Pritpal now it works
I put this line
oUI := hbqtui_sample( )
did not put any parameter while I do not understand what did you mean
in
"q_any_parent_is_you_provide_which_can_be_nil "
but anyway it works



Apolinar

calimero22

unread,
Mar 19, 2011, 9:07:00 AM3/19/11
to Harbour Users
Ok
Thank you Pritpal Bedi .
Your suggest works very fine.
This is an example:

#include "hbqtgui.ch"
PROCEDURE Main()
LOCAL application,window,ui,file
application := QApplication()
file := QFile("form.ui") // --------> form
file:open(1)
ui := QUiLoader()
window := ui:load(file)
file:close()
window:move(5,5)
window := hbqtui_form( ) --------> form
window:q_pushButton:Connect("clicked()", { || message("OK OK") } )
window:show()
application:exec()
RETURN


procedure message(x)
LOCAL oBox
oBox:= QMessageBox()
oBox:setInformativeText( x )
oBox:setWindowTitle( "Informazione" )
oBox:exec()
return


Giovanni Di Maria

Pritpal Bedi

unread,
Mar 19, 2011, 11:34:46 AM3/19/11
to Harbour Users
Hi

CORRECTION


#include "hbqtgui.ch"
PROCEDURE Main()
   LOCAL window
   window := hbqtui_form()
   window:q_pushButton:Connect("clicked()", { || message("OK OK") } )
   window:show()
   QApplication():exec()
RETURN

procedure message(x)
   LOCAL oBox
   oBox:= QMessageBox()
   oBox:setInformativeText( x )
   oBox:setWindowTitle( "Informazione" )
   oBox:exec()
return

Pritpal Bedi

calimero22

unread,
Mar 19, 2011, 11:35:55 AM3/19/11
to Harbour Users
But the file "form.ui" is necessary. If it is not present, the program
does'nt work.
Regards
Giovanni






On 19 Mar, 14:07, calimero22 <calimer...@yahoo.it> wrote:
> Ok
> Thank you Pritpal Bedi .
> Your suggest works very fine.
> ....................
>

Pritpal Bedi

unread,
Mar 19, 2011, 11:38:02 AM3/19/11
to Harbour Users
Hi

> But the file "form.ui" is necessary. If it is not present, the program
> does'nt work.

form.ui is necessary only when you link
application with hbmk2. Later at execution
time it is not needed.

Pritpal Bedi

calimero22

unread,
Mar 19, 2011, 11:49:56 AM3/19/11
to Harbour Users
Yes. It' true.
the file .ui is not necessary during the execution.
I'll put this program in my hbqt-tutorial.
Regards
Thank you Pritpal Bedi
Giovanni

************************
************************
************************
************************
************************
************************

Pritpal Bedi

unread,
Mar 19, 2011, 12:18:51 PM3/19/11
to Harbour Users
> Your suggest works very fine.

This is not a _SUGGESION_,
this is how hbQT is implemented.

Pritpal Bedi

calimero22

unread,
Mar 19, 2011, 5:55:00 PM3/19/11
to Harbour Users
Ok. Scuse me. :-)
Giovanni

calimero22

unread,
Mar 19, 2011, 6:00:56 PM3/19/11
to Harbour Users
Hi Pritpal Bedi,
I have inserted your name into the tutorial, for this argument, also.
Regards and thank you
Giovanni

******
Reply all
Reply to author
Forward
0 new messages