Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/qt/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby上的Qt无法导入任何图像/图标?_Ruby_Qt - Fatal编程技术网

Ruby上的Qt无法导入任何图像/图标?

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

我正在使用带有Qt4的Ruby。除了从文件加载图像外,其他一切都很好。我尝试使用包含在.ui文件中的资源文件加载它们。没有任何结果。我也试过代码。以这种方式,例如:

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(我想是的)

  • [QtBin]/plugins/imageformats/复制文件(如qico4.dll、qjpeg4.dll)。以类似的路径结构在项目附近创建目录。例如[OurProject]/foobar/imageformats/
  • 接下来需要使用QApplication::addLibraryPath(String)来添加新的插件路径。我用Ruby做了一个例子:

    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.
    
    类应用程序