如何在 perl 中使用 Qt GUI(用 Qt Designer 创建)?

发布于 2024-12-17 22:42:50 字数 406 浏览 0 评论 0原文

我已经在 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 编写的示例。有人可以帮助我吗?

I have created Qt GUI in Qt Designer and compiled it (using puic4) to gui.pm.
Now, I'd like to use it in my Perl application, but I'm stuck because I don't know how to create window object.

I have following code in 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();

I just need to create window object, but I can't find any example written in perl. Anyone can help me?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

隔岸观火 2024-12-24 22:42:50

我在源存储库中找到了以下解决方案:

BUILD_DIR/Qt4-0.99.0/qtgui/examples/designer/calculatorform
  1. 构建 Ui 模块
 > 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" );
....
  1. 创建启动模块 MainWidow.pm。您必须“转换”UI 类。
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);
}
  1. 编写应用程序 perl 脚本 Main.pl:
#!/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();

问候 huck

I found the following solution in the source repository:

BUILD_DIR/Qt4-0.99.0/qtgui/examples/designer/calculatorform
  1. Build your Ui-Module
 > 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" );
....
  1. Create a launch module MainWidow.pm. You have to "cast" the UI-class.
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);
}
  1. Write the application perl script Main.pl:
#!/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();

regards huck

蝶…霜飞 2024-12-24 22:42:50

假装我不知道 QTDesigner ,该示例来自 http://search.cpan.org/ dist/Qt/MANIFEST 你会遵循吗?
我认为,您选择一个 .ui 示例,运行 makefile(或手动),然后您就有一个可以调用的模块(即 my $w = my $chat = ChatMainWindow(); ).

Pretend that I don't know about QTDesigner , which example from http://search.cpan.org/dist/Qt/MANIFEST would you follow?
I think , you pick one of the .ui examples, run the makefile (or by hand), and then you have a module you can call (ie my $w = my $chat = ChatMainWindow(); ).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文