tags:

views:

126

answers:

3

I'm learning python and Qt to create graphical desktop apps. I designed the UI with Qt Designer and converted the .ui to .py using pyuic, according to the tutorial I'm following, I should be able to run my app. but when I do it, a terminal window opens and it says:

cd '/Users/andresacevedo/' && '/opt/local/bin/python2.6'  '/Users/andresacevedo/aj.pyw'  && echo Exit status: $? && exit 1
Exit status: 0
logout

[Process completed]

Does it means that the app. exited without errors? then why I don't see the UI that I designed?

P.S. I'm using OS X Snow leopard

Thanks,


Edit (This is the source code of my app.)

# -*- coding: utf-8 -*-

# Form implementation generated from reading ui file 'principal.ui'
#
# Created: Sat Oct 17 15:07:17 2009
#      by: PyQt4 UI code generator 4.6
#
# WARNING! All changes made in this file will be lost!

from PyQt4 import QtCore, QtGui

class Ui_MainWindow(object):
    def setupUi(self, MainWindow):
        MainWindow.setObjectName("MainWindow")
        MainWindow.resize(379, 330)
        self.centralwidget = QtGui.QWidget(MainWindow)
        self.centralwidget.setObjectName("centralwidget")
        MainWindow.setCentralWidget(self.centralwidget)
        self.menubar = QtGui.QMenuBar(MainWindow)
        self.menubar.setGeometry(QtCore.QRect(0, 0, 379, 22))
        self.menubar.setObjectName("menubar")
        self.menuMenu_1 = QtGui.QMenu(self.menubar)
        self.menuMenu_1.setObjectName("menuMenu_1")
        MainWindow.setMenuBar(self.menubar)
        self.statusbar = QtGui.QStatusBar(MainWindow)
        self.statusbar.setObjectName("statusbar")
        MainWindow.setStatusBar(self.statusbar)
        self.actionOpcion_1 = QtGui.QAction(MainWindow)
        self.actionOpcion_1.setObjectName("actionOpcion_1")
        self.menuMenu_1.addAction(self.actionOpcion_1)
        self.menubar.addAction(self.menuMenu_1.menuAction())

        self.retranslateUi(MainWindow)
        QtCore.QMetaObject.connectSlotsByName(MainWindow)

    def retranslateUi(self, MainWindow):
        MainWindow.setWindowTitle(QtGui.QApplication.translate("MainWindow", "MainWindow", None, QtGui.QApplication.UnicodeUTF8))
        self.menuMenu_1.setTitle(QtGui.QApplication.translate("MainWindow", "Menu 1", None, QtGui.QApplication.UnicodeUTF8))
        self.actionOpcion_1.setText(QtGui.QApplication.translate("MainWindow", "Opcion 1", None, QtGui.QApplication.UnicodeUTF8))
+1  A: 

The problem is that your python code is merely defining a class, but has no main program which invokes the class or causes QT to pop up a window.

It seems a little unusual that your Ui_MainWindow class isn't actually a subclass of QMainWindow; it isn't a widget itself, but it merely configures the MainWindow which gets passed to it. But I think that can still work, with something like the (untested) code below.

import sys
from PyQt4 import Qt

# (define class Ui_MainWindow here...)

if __name__=="__main__":

    app=Qt.QApplication(sys.argv)
    mywin = Qt.QMainWindow()
    myui = Ui_MainWindow(mywin)
    myui.setupUI(mywin)

    app.connect(app, Qt.SIGNAL("lastWindowClosed()"),
                app, Qt.SLOT("quit()"))
    mywin.show()

    app.exec_()
D Adler
Qt3 example, his code is Qt4.
Lukáš Lalinský
+1  A: 

I'm doing very newbie questions, well because I'm a pyqt newbie... what was happening was that I called pyuic without the -x attribute, so the code just creates the UI but not the code for running it, anyway your help was very valuable.

MrAn3
A: 

The code you get from Qt Designer is only a class with set of widgets. It is not an application. See the PyQt manual for info how to use the Designer code in your applications. I'd suggest to read some Qt tutorial first, write some "hello world" application first, and only then write applications that use Designer forms.

Lukáš Lalinský