ryanmelt / qtbindings

An easy to install gem version of the Ruby bindings to Qt
http://github.com/ryanmelt/qtbindings
Other
340 stars 63 forks source link

Native window not accessible in OSX - crash #77

Closed patrickhno closed 10 years ago

patrickhno commented 10 years ago

Unless I am seriously mistaken it seems the effectiveWinId is not a valid pointer to a NSView or NSViewRef accessible through qtbindings - as is what it seems to be in the Qt code.

As none of the examples does makeKeyAndOrderFront successfully and show + raise don't fully activate the application we need to do this ourselves it seems. (It brings the windows to front, but you have to cmd-tab back and fourth for the application menu to activate as well.) My understanding from googling is that this issue is a Qt issue, thus the only way around it is to use the native OSX API directly.

But sure, enlighten me if I'm lost.

Crash (modified examples/mainwindow/application/main.rb):

require 'Qt'
require './mainwindow.rb'
require 'ffi'

module ObjC
  extend FFI::Library
  ffi_lib 'objc'

  attach_function :sel_registerName, [:string], :pointer
  attach_function :objc_msgSend, [:pointer, :pointer, :varargs], :pointer

  def self.msgSend( id, selector, *args )
    selector = sel_registerName(selector)
    objc_msgSend( id, selector, *args )
  end
end

app = Qt::Application.new(ARGV)
mainWin = MainWindow.new
mainWin.show

puts mainWin.effectiveWinId.inspect
ptr = FFI::Pointer.new(:void,mainWin.effectiveWinId)
puts ptr.inspect
puts ObjC.msgSend(ptr,"class").inspect # crash

app.exec
ryanmelt commented 10 years ago

I have recreated this but don't have a fix. Sorry. Please submit a pull request if you figure it out.