我在Qt Designer中创建了Qt GUI并将其编译(使用puic4)到gui.pm. 现在,我想在我的Perl应用程序中使用它,但我被卡住了,因为我不知道如何创建窗口对象。
我在start.pl中有以下代码:
use strict;
use QtCore4;
use QtGui4;
use gui; #compiled gui ('Ui_MainWindow' package)
my $a = Qt::Application(\@ARGV);
my $w = ??? #assign window object to $w
$w->show();
exit $a->exec();
我只需要创建窗口对象,但我找不到用perl编写的任何示例。有人可以帮帮我吗?
答案 0 :(得分:2)
假装我不了解QTDesigner,您会关注http://search.cpan.org/dist/Qt/MANIFEST中的哪个示例?
我想,你选择一个.ui例子,运行makefile(或手工),然后你就可以调用一个模块(即my $w = my $chat = ChatMainWindow();
)。
答案 1 :(得分:2)
我在源代码库中找到了以下解决方案:
BUILD_DIR/Qt4-0.99.0/qtgui/examples/designer/calculatorform
> puic4 Window.ui -o Ui_MainWindow.pm
#################################################################################
## Form generated from reading UI file 'Window.ui'
##
## Created: Do. Aug 27 20:57:17 2015
## by: Qt User Interface Compiler version 4.8.2
##
## WARNING! All changes made in this file will be lost when recompiling UI file!
################################################################################
package Ui_MainWindow;
use strict;
use warnings;
use QtCore4;
use QtGui4;
sub centralwidget { return shift->{centralwidget}; }
sub pushButton { return shift->{pushButton}; }
sub pushButton_2 { return shift->{pushButton_2}; }
sub menubar { return shift->{menubar}; }
sub statusbar { return shift->{statusbar}; }
sub setupUi {
my ( $class, $mainWindow ) = @_;
my $self = bless {}, $class;
if ( !defined $mainWindow->objectName() ) {
$mainWindow->setObjectName( "mainWindow" );
....
package MainWindow;
use strict;
use warnings;
use QtGui4;
# Cast the exact Qt Type for your UI class
use QtCore4::isa qw( Qt::MainWindow );
use Ui_MainWindow;
sub NEW {
my ( $class, $parent ) = @_;
$class->SUPER::NEW($parent);
this->{ui} = Ui_MainWindow->setupUi(this);
}
#!/usr/bin/perl
use strict;
use warnings;
use QtCore4;
use QtGui4;
use MainWindow;
sub main {
my $app = Qt::Application( \@ARGV );
my $win = MainWindow();
$win->show();
exit $app->exec();
}
main();
问哈克