开发者

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

开发者 https://www.devze.com 2023-04-08 16:43 出处:网络
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.

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:

  • no qtruby library on windows
  • Ruby 1.9.x + Qt4Ruby…. a pipe dream???
  • qtruby4 LoadError in ruby 1.9.1 / win32 for qtruby4-2.1.0

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:

  • this one's in German
  • gpg4win: help

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:

  • help -- qt, ruby, ms-windows?

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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消