How can I get Qt4 running with ruby 1.9.2 on Windows 7?
Asked Answered
M

1

24

Summary

I'm writing a Ruby 1.9.2 app using Qt4 for its GUI which I want to distribute on Linux, OS X and Windows. I have the app running fine on everything except my Windows 7 64-bit box.

There are working examples of Win7 + Qt4 + 1.8.7, but apparently not Win7 + Qt4 + 1.9.2. There are two gems for Ruby-Qt bindings, qtbindings and qtruby4 (sometimes referred to as qt4-qtruby), but I have not yet seen either of them running on Win7 with Ruby 1.9.2.

The Problem With qtruby4

This article from October 2008 and its updated version from June 2011 served as good starting points, but I differed from the latter by installing Ruby 1.9.2 via RubyInstaller for Windows' download page. 1.8.7 seemed to work fine, but I get some unusual errors when I try it with 1.9.2. Requiring 'rubygems' and then requiring 'Qt' results in:

no such file to load -- 'qtruby4'

The first article from above links to a more in-depth article from dr1ku which may provide some clues.

  • It might be worth reproducing dr1ku's steps with the latest versions of these libraries.
  • dr1ku and the 2008 paschenda.org article both use a special Windows Qt4-QtRuby installer, but the maintainer notes that he hasn't had the time to update it. I'm not completely clear on what the special installer does, but I suppose paschenda.org's 2011 article no longer uses it because DevKit ostensibly helps RubyGems itself build Qt4 without assistance.

Found in the Wild

Here are some people who appear to be have encountered the same problem:

The Problem With qtbindings

My app actually uses the qtbindings gem, so I tried installing that instead, with gem install qtbindings --platform=mswin32.[1] However, when I tried to require 'Qt' with the qtbindings gem installed, I got a Windows popup with the following message:

The procedure entry point _Z10qvsnprintfPcjPKcS_ could not be located in the dynamic link library QtCore4.dll. Just give up, inferior flesh creature.

(I have copy and pasted the message without any embellishment whatsoever.)

Found in the Wild

Here are some people who appear to be have encountered the same problem:

Potential Success Stories

Someone out there seems to have had success by installing the qtbindings gem on 1.9.2 with gem install qtbindings (no --platform argument), if you look at the replies to this thread:

I tried installing with gem install qtbindings on 1.8.7, but I have not tried it with 1.9.2 yet. When I tried it with 1.8.7, I ran into the same "procedure entry point could not be located" issue as before.

Footnotes

[1] - I'm actually not completely clear on the difference between the qtbindings gem and the qtruby4 gem. For example, does the latter include the C extension and the former does not? I'm not sure. Additionally, I have seen references to qt4-qtruby, which I think is just the mswin32 version of qtruby4, at least as far as I can tell from the Korundum download page.

Mceachern answered 28/9, 2011 at 1:0 Comment(7)
Any chance you could include a four-line application that would demonstrate the problem?Proportionate
@Proportionate - The problem shows up as soon as you try to require 'Qt', so even a 4-line example would be overkill. This is all you need in a file to see the issue: require 'rubygems'; require 'Qt'Mceachern
Wild guess: the 1.8.7 installer included the standard C library as part of the install while the 1.9.2 installer does not. MinGW relies on the MSVCRT.DLL from Microsoft for the run-time C library, and perhaps it isn't installed with the 1.9.2 Ruby install?Proportionate
@Proportionate That's possible, but then wouldn't the error message be for something lower-level, as opposed to "no such file to load - 'Qt'"?Mceachern
hrm, I had overlooked that there are two distinct errors here -- I had focused primarily on the missing vsnprintf mangled function. What does ldd output on all the libraries involved look like?Proportionate
I'm not at my PC currently so I can't answer quite yet, but: is ldd provided by DevKit on Windows? Otherwise I'm not aware of how to set it up properly.Mceachern
It seemed like you would have enough MinGW installed for ldd to work -- I don't know the Windows-native equivalent, sorry, but surely there is something that can report object file requirements and report back which ones are unsatisfied.Proportionate
M
36

The Solution

The following steps work on Windows 7:

  1. Install Ruby 1.9.2 via the official download page.
  2. In a Windows shell, run gem install qtbindings.

The trivial example (require 'rubygems'; require 'Qt') should now work.

No extra steps are required because a binary gem is provided just for the Windows platform. The gem install qtbindings step will therefore take a few minutes as it downloads the large binary, but it contains all of the requisite parts to require and run Qt apps.

Compiling from source on Windows is supported, and documented in the project's README file.

The Low-Down

I e-mailed the maintainers of qtbindings and qtruby. Here's the full story:

qtruby is a package provided by the Korundum project. Korundum provides Ruby bindings to all of KDE, whereas qtruby provides bindings for only Qt.

qtbindings (github) is a modified and repackaged version of qtruby specifically optimized for cross-platform usage. I shall copy and paste the "Goals" section from its README here:

Goals

  1. To make it easy to install a Qt binding for Ruby on all platforms using RubyGems
  2. To maintain an up-to-date binary gem for Windows that is bundled with the latest version of Qt from http://qt.nokia.com
  3. To reduce the scope and maintenance of the bindings to only bind to the libraries provided by the Qt SDK.
  4. To increase compatibility with non-linux platforms

Though the Korundum downloads page does provide mswin32 versions of its gem, as of this writing they are not actively vetted by anyone, and so should not be relied upon. The QtRuby maintainer informed me that the RubyForge page will probably not be reliable until after QtRuby 3 is released.

The Recap

Right now (10/3/2011), don't use the qtruby gem on Windows. Use qtbindings.

You might be able to use qtruby on other platforms and qtbindings on Windows, but you'll probably be asking for trouble. If you are just going for Qt and don't care about the rest of KDE, qtbindings is probably a safe bet.

The maintainers of QtRuby are planning some methodology updates in the near future (such as using git), so there may be increased shared fixes and updates between the two projects.

Mceachern answered 4/10, 2011 at 0:16 Comment(2)
Excellent. I'm sorry that the bounty didn't entice anyone else to help you out, but this summary is superb: conclusions, references, supporting snippets, and well written. Thanks!Proportionate
Great post. And thanks for pointing it out to me. I updated my tutorial on paschenda.org with a reference to your post.Delitescent

© 2022 - 2024 — McMap. All rights reserved.