Ruby上的Qt无法导入任何图像/图标?
我正在使用带有Qt4的Ruby。除了从文件加载图像外,其他一切都很好。我尝试使用包含在.ui文件中的资源文件加载它们。没有任何结果。我也试过代码。以这种方式,例如:Ruby上的Qt无法导入任何图像/图标?,ruby,qt,Ruby,Qt,我正在使用带有Qt4的Ruby。除了从文件加载图像外,其他一切都很好。我尝试使用包含在.ui文件中的资源文件加载它们。没有任何结果。我也试过代码。以这种方式,例如: class Window < Qt::Window def initialize filename = "images/icon.ico" icon = Qt::Icon.new filename setWindowIcon icon puts File.exist? filename
class Window < Qt::Window
def initialize
filename = "images/icon.ico"
icon = Qt::Icon.new filename
setWindowIcon icon
puts File.exist? filename
puts Qt::File.new(filename).exists
puts !icon.isNull
puts icon.name
end
end
类窗口true
true
true
<empty line>
true
真的
真的
当我尝试将图像加载为QPixmap并调整其大小时,我得到了错误信息:“空的QPixmap无法调整大小”。
图像位于“images/icon.ico”中脚本的相对位置,但我尝试使用绝对路径(例如:e:/Ruby/Project/images/icon.ico)。结果是一样的。我在Windows下工作,但路径在Qt之外工作。例如,使用Yaml文件。加载文件。ui工作得很好。那么问题出在哪里呢?我已经找到了关于这个问题的详细信息。问题是在Qt使用的所有语言上加载plugins libraries.DLL(我想是的)
class App < Qt::Application
def initialize
super ARGV
addLibraryPath 'foobar' # There is qico4.dll
icon = Qt::Icon.new 'images/icon.ico' # Now I can use .ico!
setWindowIcon icon
# ... show windows et cetera.
end
end
App.new.exec # All of windows now have icon from icon.ico.
类应用程序