[Kde-bindings] QtRuby bindings extension initialization

Richard Dale Richard_Dale at tipitina.demon.co.uk
Tue Jul 8 17:38:09 UTC 2003


I've got the overall top level framework of the Qt ruby extension working ok. 
The file 'Qt.cpp' is the equivalent of 'Qt.xs' in PerlQt, and 'qtruby.rb' is 
the equivalent of 'Qt.pm'. 

When the extension is loaded, he function Init_Qt() in Qt.so is called, and 
that loads the qtruby.rb file and then calls Qt::Internal.init() method to do 
the package initilization. 

The various methods that were in PerlQt Qt::_internal can be called - now 
called in Qt::Internal in ruby. qtruby.rb looks like this:

module Qt
	module Internal
		def init_class(c)
			classId = idClass(c)
			insert_pclassid(c, classId)
			isa = getIsa(classId)
#			for parent in isa
#				puts parent
#			end
			installautoload(c)
		end
		
		def init()
#    		installthis("__PACKAGE__")
    		installthis("Qt::base")
			classes = getClassList()
			for c in classes
				init_class(c)
			end
		end
	end
end

The extension Makefile can be built with this command or similar:

ruby extconf.rb --with-smoke-dir=/opt/kde3 \ 
--with-qt-dir=/home/duke/src/kde/HEAD/qt-copy

Then I had to change this line in the generated Makefile:
LOCAL_LIBS =

To:
LOCAL_LIBS =  -lsmokeqt -lqt-mt -lstdc++

An example program is 'tryit.rb':

require 'Qt'

x = QWidget.new(5)
x.baz(5)

The initialization addes initialize() and method_missing() hooks back to the 
ruby interface. The example above produces this output to show the two method 
hooks have been called ok:

baldhead duke 1980% ruby tryit.rb
In Init_Qt
In initialise, argc: 1, self name: QWidget
In method_missing(argc: 2, argv[0]: baz argv[1]: 5)

So the next step is to look up a method in smoke, marshall the args and 
execute it..

-- Richard
-------------- next part --------------
A non-text attachment was scrubbed...
Name: qtruby_0.2.tar.gz
Type: application/x-tgz
Size: 24728 bytes
Desc: not available
URL: <http://mail.kde.org/pipermail/kde-bindings/attachments/20030708/ba718e68/attachment.bin>


More information about the Kde-bindings mailing list