How to use Qt GUI (created using Qt Designer) in perl?

I created the Qt GUI in Qt Designer and compiled it (using puic4) in gui.pm. Now I would like to use it in my Perl application, but I am stuck because I do not know how to create a window object.

I have the 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 a window object, but I cannot find any example written in perl. Can anybody help me?

+4
source share
2 answers

In the source repository, I found the following solution:

 BUILD_DIR/Qt4-0.99.0/qtgui/examples/designer/calculatorform 
  • 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 the starter module MainWidow.pm. You must "distinguish" 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. Record 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(); 

considers huck

+2
source

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

+2
source

Source: https://habr.com/ru/post/1383235/


All Articles