问题
I'm trying to create a simple application, written in Ruby via Qt. I designed a form (MainForm) in a Qt Designer and translated it via rbuic4
to the Ruby code representation. The pure untouched result has four methods, and looks like this:
=begin
** Form generated from reading ui file 'stackover.ui'
**
** Created: Р’С‚ 24. РЅРѕСЏ 21:15:02 2009
** by: Qt User Interface Compiler version 4.3.1
**
** WARNING! All changes made in this file will be lost when recompiling ui file!
=end
class Ui_MainWindow
attr_reader :centralwidget
attr_reader :pushButton
attr_reader :listView
attr_reader :menubar
attr_reader :statusbar
def setupUi(mainWindow)
mainWindow.setObjectName("mainWindow")
@centralwidget = Qt::Widget.new(mainWindow)
@centralwidget.setObjectName("centralwidget")
@pushButton = Qt::PushButton.new(@centralwidget)
@pushButton.setObjectName("pushButton")
@pushButton.setGeometry(Qt::Rect.new(10, 10, 75, 23))
@listView = Qt::ListView.new(@centralwidget)
@listView.setObjectName("listView")
@listView.setGeometry(Qt::Rect.new(10, 40, 431, 192))
mainWindow.setCentralWidget(@centralwidget)
@menubar = Qt::MenuBar.new(mainWindow)
@menubar.setObjectName("menubar")
@menubar.setGeometry(Qt::Rect.new(0, 0, 451, 21))
mainWindow.setMenuBar(@menubar)
@statusbar = Qt::StatusBar.new(mainWindow)
@statusbar.setObjectName("statusbar")
mainWindow.setStatusBar(@statusbar)
retranslateUi(mainWindow)
size = Qt::Size.new(451, 276)
size = size.expandedTo(mainWindow.minimumSizeHint())
mainWindow.resize(size)
Qt::MetaObject.connectSlotsByName(mainWindow)
end # setupUi
def setup_ui(mainWindow)
setupUi(mainWindow)
end
def retranslateUi(mainWindow)
mainWindow.setWindowTitle(Qt::Application.translate("MainWindow", "MainWindow", nil, Qt::Application::UnicodeUTF8))
@pushButton.setText(Qt::Application.translate("MainWindow", "PushButton", nil, Qt::Application::UnicodeUTF8))
end # retranslateUi
def retranslate_ui(mainWindow)
retranslateUi(mainWindow)
end
end
module Ui
class MainWindow < Ui_MainWindow
end
end # module Ui
The major idea is to create a Ruby-Qt application, to run my small Ruby apps with GUI - as for now I don't need all the power of Qt library.
I'm aware of this great example, but it shows off a different generated code for the .ui file. Or did they managed to alter it somehow? Anyway, their example works fine, while I can't make my own working properly.
I just don't know what to do with my generated file, how to go further and make a connection with my Ruby program... Maybe my rbuic4
is wrong? Or am I'm running it with incorrect options (I'm an -o
option) to get the arachnoid-like template?
回答1:
The easiest way to actually DO something with your code is to regenerate it like this:
rbuic4 -x stackover.ui -o stackover.ui.rb
Than run the generated stackover.ui.rb file like this:
ruby stackover.ui.rb
Hope it helps.
回答2:
Well, Ok. As far as I cannot find the exact use of the mentioned generated file, I decided to copy-paste component init. code to another Ruby-Qt template app, where's everything is clear for me. Thus QtDesigner and rbui4
are only useful for quick form design/translation, which should be then followed by all required manual polishing.
Waiting for newer version of rbuic4
and QtRuby support of urgent version of Qt.
来源:https://stackoverflow.com/questions/1792318/ruby-creating-a-simple-application-in-qt