Qt4 bindings, threads

I couldn’t find a mailinglist for the Qt4 Ruby bindings, so I try here.
It
seems the Qt4 Ruby bindings lack Qt::Thread. So how do I create a
Thread? Do
I use Ruby’s build-in? I need a thread because I need to read from a
UNIX
domain socket (blocking), and pass the data to the GUI. Thanks for any
help!

/D

On Dec 25, 2007, at 6:36 PM, daniel åkerud wrote:

I couldn’t find a mailinglist for the Qt4 Ruby bindings, so I try
here. It
seems the Qt4 Ruby bindings lack Qt::Thread. So how do I create a
Thread? Do
I use Ruby’s build-in? I need a thread because I need to read from a
UNIX
domain socket (blocking), and pass the data to the GUI. Thanks for
any help!

There’s no Qt::Thread because Ruby lacks support for native threads
(at least, for the moment), so it’s not really feasible to implement.

The most common workaround is to use a Qt::SocketNotifier to pipe data
into the application over a socket so that your GUI isn’t blocking
while the data is coming in.

Caleb

Thanks for the quick answer. I’ll look up on the non-blocking IO.

I noticed that Qt::Application.exec() stops all Ruby threads as well. So
no
go either way.

Anyone knows if there are plans for the future to support threading and
Qt?

/D

qtruby4 unfortunately lacks QSocketNotifier as well. The Ruby UNIXSocket
class contains a method called read_nonblock which gives me some hope
though
:slight_smile:

/D

Alle mercoledì 26 dicembre 2007, daniel åkerud ha scritto:

I couldn’t find a mailinglist for the Qt4 Ruby bindings, so I try here. It
seems the Qt4 Ruby bindings lack Qt::Thread. So how do I create a Thread?
Do I use Ruby’s build-in? I need a thread because I need to read from a
UNIX domain socket (blocking), and pass the data to the GUI. Thanks for any
help!

/D

There’s a forum for qtruby. It’s at rubyforge, and the name of the
project is
korundum. The address of the forum is:
http://rubyforge.org/forum/forum.php?forum_id=723

As for your question about threads, they’re discussed in these two
threads in
the forum:
http://rubyforge.org/forum/message.php?msg_id=3319
http://rubyforge.org/forum/forum.php?thread_id=14559&forum_id=723

I hope this helps

Stefano

If anyone has the same problem in the future: I solved this problem by
using
a Qt::Timer, that polls the UNIX domain socket every 100ms. At every
poll it
reads data with socket.read_nonblock until it throws a Errno::EAGAIN,
like
this:

 40     # poll data from socket, until there is no more
 41     begin
 42       begin # loop while read_nonblock returns data
 43         new_data, addr_arr = @socket.read_nonblock(128)
 44         data << new_data
 45       end while true
 46     rescue Errno::EAGAIN
 47       # no more data
 48     end

Much cleaner than using a thread, IMO.

/D

On Dec 26, 2007 10:35 AM, Stefano C. [email protected]
wrote:

/D
http://rubyforge.org/forum/forum.php?thread_id=14559&forum_id=723

I hope this helps

Stefano

Thank you very much!!

/D

On Dec 26, 1:05 am, daniel åkerud [email protected] wrote:

qtruby4 unfortunately lacks QSocketNotifier as well. The Ruby UNIXSocket
class contains a method called read_nonblock which gives me some hope though
:slight_smile:
Your version of the Smoke library that QtRuby uses should have the
QSocketNotifier class, my version of QtRuby certainly has it. Try
using the 'rbqtapi ’ tool to find if it is there:

$ rbqtapi QSocketNotifier
enum QSocketNotifier::Exception
QSocketNotifier* QSocketNotifier::QSocketNotifier(int,
QSocketNotifier::Type)
QSocketNotifier* QSocketNotifier::QSocketNotifier(int,
QSocketNotifier::Type, QObject*)

– Richard

On Dec 26, 2007 11:13 PM, daniel Ã¥kerud [email protected] wrote:

QSocketNotifier::Type)
from /usr/bin/rbqtapi:11
Maintainer: Ubuntu MOTU Developers [email protected]
But perhaps i’m missing something fundamental here :smiley:

/D

Hmm, I made a link after delving deeper into the error:
sudo ln -s /usr/bin/rbqtapi /usr/bin/rbqt4api

and then it worked, gave me this answer:

da@brutus:~$ rbqt4api QSocketNotifier
enum QSocketNotifier::Exception
QSocketNotifier* QSocketNotifier::QSocketNotifier(int,
QSocketNotifier::Type)
QSocketNotifier* QSocketNotifier::QSocketNotifier(int,
QSocketNotifier::Type, QObject*)
enum QSocketNotifier::Read
enum QSocketNotifier::Write
void QSocketNotifier::activated(int)
bool QSocketNotifier::event(QEvent*)
bool QSocketNotifier::isEnabled() const
const QMetaObject* QSocketNotifier::metaObject() const
int QSocketNotifier::qt_metacall(QMetaObject::Call, int, void**)
void QSocketNotifier::setEnabled(bool)
int QSocketNotifier::socket() const
static const QMetaObject QSocketNotifier::staticMetaObject()
static QString QSocketNotifier::tr(const char*)
static QString QSocketNotifier::tr(const char*, const char*)
QSocketNotifier::Type QSocketNotifier::type() const
void QSocketNotifier::~QSocketNotifier()

I don’t know what I did wrong previously… I’ll definetly update my
code
:smiley:

Thanks for letting me know about the cool utility.

/D

On Dec 26, 2007 10:25 PM, [email protected]
[email protected]
wrote:

– Richard

I use the packages in Kubuntu Gutsy Gibbon. rbqtapi doesn’t work for me:

da@brutus:~$ rbqtapi
/usr/bin/rbqtapi:11:in `require’: no such file to load – Qt (LoadError)
from /usr/bin/rbqtapi:11
da@brutus:~$

This is the qtruby version:

da@brutus:~$ dpkg -s libqt4-ruby
Package: libqt4-ruby
Status: install ok installed
Priority: optional
Section: interpreters
Installed-Size: 56
Maintainer: Ubuntu MOTU Developers [email protected]
Architecture: all
Version: 1.4.9-4ubuntu1
Depends: libqt4-ruby1.8
Description: ruby bindings for the Qt4 GUI library
Smoke-based ruby bindings for Qt4, the Trolltech GUI library.
.
This is a dependency package to point to the current version
of ruby.
Original-Maintainer: Vincent F. [email protected]

But perhaps i’m missing something fundamental here :smiley:

/D

On Dec 26, 2007 7:22 PM, daniel Ã¥kerud [email protected] wrote:

43         new_data, addr_arr = @socket.read_nonblock(128)
44         data << new_data
45       end while true
46     rescue Errno::EAGAIN
47       # no more data
48     end

Much cleaner than using a thread, IMO.

/D

Update to this: QSocketNotifier is indeed they way to go. I think I
tried
Qt::QSocketNotifier instead of Qt::SocketNotifier by mistake earlier.

/D