qt4 bindings, threads

D

daniel åkerud

[Note: parts of this message were removed to make it a legal post.]

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
 
C

Caleb Tennis

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

There's no Qt::Thread because Ruby lacks support for native threads =20
(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 =20=

into the application over a socket so that your GUI isn't blocking =20
while the data is coming in.

Caleb
 
D

daniel åkerud

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
 
D

daniel åkerud

qtruby4 unfortunately lacks QSocketNotifier as well. The Ruby UNIXSocket
class contains a method called read_nonblock which gives me some hope thoug=
h
:)

/D
 
S

Stefano Crocco

Alle mercoled=EC 26 dicembre 2007, daniel =E5kerud 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 a= ny
help!

/D

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

As for your question about threads, they're discussed in these two threads =
in=20
the forum:
http://rubyforge.org/forum/message.php?msg_id=3D3319
http://rubyforge.org/forum/forum.php?thread_id=3D14559&forum_id=3D723

I hope this helps

Stefano
 
D

daniel åkerud

Alle mercoled=EC 26 dicembre 2007, daniel =E5kerud ha scritto:

There's a forum for qtruby. It's at rubyforge, and the name of the projec= t
is
korundum. The address of the forum is:
http://rubyforge.org/forum/forum.php?forum_id=3D723

As for your question about threads, they're discussed in these two thread= s
in
the forum:
http://rubyforge.org/forum/message.php?msg_id=3D3319
http://rubyforge.org/forum/forum.php?thread_id=3D14559&forum_id=3D723

I hope this helps

Stefano

Thank you very much!!

/D
 
D

daniel åkerud

If anyone has the same problem in the future: I solved this problem by usin=
g
a Qt::Timer, that polls the UNIX domain socket every 100ms. At every poll i=
t
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 =3D @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
 
R

richard.j.dale

qtruby4 unfortunately lacks QSocketNotifier as well. The Ruby UNIXSocket
class contains a method called read_nonblock which gives me some hope though
:)
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
 
D

daniel åkerud

[Note: parts of this message were removed to make it a legal post.]

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

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.
 
D

daniel åkerud

On Dec 26, 2007 10:25 PM, (e-mail address removed) <
:

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 Fourmond <[email protected]>

But perhaps i'm missing something fundamental here :-D

/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
:-D

Thanks for letting me know about the cool utility.

/D
 
D

daniel åkerud

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, lik= e
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 =3D @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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,128
Latest member
ElwoodPhil
Top