• 5759阅读
  • 3回复

QT3怎样进行多窗口编程? [复制链接]

上一主题 下一主题
离线anthonymo200
 
只看楼主 倒序阅读 楼主  发表于: 2010-11-09
— 本帖被 XChinux 执行加亮操作(2010-11-11) —
在ARM9上开发一个GUI界面, 基本上选定用QT3(qt-3.3.8b)来开发。 使用designer 创建了两个ui文件, 一个是mainwinform.ui , 一个是dialogform.ui。

在mainwinform.ui里面放了两个按钮, 一个是nextButton , 一个是closeButton按钮,  我希望程序运行后, 按一下mainwinform里面的nextButton就弹出

dialogform界面。编译, 运行程序, 出现主界面。按nextButton. 却没有任何反应。 现在贴出源码, 请高手指点, 问题出在哪里, 

main.cpp  //源码
#include <qapplication.h>
#include "mainwinform.h"
int main( int argc, char ** argv )
{
    QApplication a( argc, argv );
    mainwinForm w;
    w.show();
    a.connect( &a, SIGNAL( lastWindowClosed() ), &a, SLOT( quit() ) );
    return a.exec();
}

mainwinform.h//头文件
/****************************************************************************
** Form interface generated from reading ui file 'mainwinform.ui'
**
** Created: Tue Nov 9 17:36:07 2010
**
** WARNING! All changes made in this file will be lost!
****************************************************************************/
#ifndef MAINWINFORM_H
#define MAINWINFORM_H
#include <qvariant.h>
#include <qwidget.h>
#include "dialogform.h"
class QVBoxLayout;
class QHBoxLayout;
class QGridLayout;
class QSpacerItem;
class QPushButton;
class mainwinForm : public QWidget
{
    Q_OBJECT
public:
    mainwinForm( QWidget* parent = 0, const char* name = 0, WFlags fl = 0 );
    ~mainwinForm();
    QPushButton* exitButton;
    QPushButton* nextButton;
protected:
protected slots:
    virtual void languageChange();
private:
    dialogForm dg1form;
    virtual void on_nextButton_clicked();
};
#endif // MAINWINFORM_H


mainwinform.cpp //源码
/****************************************************************************
** Form implementation generated from reading ui file 'mainwinform.ui'
**
** Created: Tue Nov 9 17:36:10 2010
**
** WARNING! All changes made in this file will be lost!
****************************************************************************/
#include "mainwinform.h"
#include <qvariant.h>
#include <qpushbutton.h>
#include <qlayout.h>
#include <qtooltip.h>
#include <qwhatsthis.h>
#include <qimage.h>
#include <qpixmap.h>
#include "mainwinform.ui.h"
/*
 *  Constructs a mainwinForm as a child of 'parent', with the
 *  name 'name' and widget flags set to 'f'.
 */
mainwinForm::mainwinForm( QWidget* parent, const char* name, WFlags fl )
    : QWidget( parent, name, fl )
{
    if ( !name )
 setName( "mainwinForm" );
    exitButton = new QPushButton( this, "exitButton" );
    exitButton->setGeometry( QRect( 450, 390, 80, 32 ) );
    nextButton = new QPushButton( this, "nextButton" );
    nextButton->setGeometry( QRect( 280, 390, 70, 32 ) );
    languageChange();
    resize( QSize(600, 480).expandedTo(minimumSizeHint()) );
    clearWState( WState_Polished );
    // signals and slots connections
    connect( exitButton, SIGNAL( clicked() ), this, SLOT( close() ) );
}
/*
 *  Destroys the object and frees any allocated resources
 */
mainwinForm::~mainwinForm()
{
    // no need to delete child widgets, Qt does it all for us
}
/*
 *  Sets the strings of the subwidgets using the current
 *  language.
 */
void mainwinForm::languageChange()
{
    setCaption( tr( "main win Form" ) );
    exitButton->setText( tr( "&exit" ) );
    exitButton->setAccel( QKeySequence( tr( "Alt+E" ) ) );
    nextButton->setText( tr( "&next" ) );
    nextButton->setAccel( QKeySequence( tr( "Alt+N" ) ) );
}

dialogform.h//头文件
/****************************************************************************
** Form interface generated from reading ui file 'dialogform.ui'
**
** Created: Tue Nov 9 17:36:07 2010
**
** WARNING! All changes made in this file will be lost!
****************************************************************************/
#ifndef DIALOGFORM_H
#define DIALOGFORM_H
#include <qvariant.h>
#include <qdialog.h>
class QVBoxLayout;
class QHBoxLayout;
class QGridLayout;
class QSpacerItem;
class dialogForm : public QDialog
{
    Q_OBJECT
public:
    dialogForm( QWidget* parent = 0, const char* name = 0, bool modal = FALSE, WFlags fl = 0 );
    ~dialogForm();

protected:
protected slots:
    virtual void languageChange();
};
#endif // DIALOGFORM_H

dialogform.cpp //源码
/****************************************************************************
** Form implementation generated from reading ui file 'dialogform.ui'
**
** Created: Tue Nov 9 17:36:10 2010
**
** WARNING! All changes made in this file will be lost!
****************************************************************************/
#include "dialogform.h"
#include <qvariant.h>
#include <qlayout.h>
#include <qtooltip.h>
#include <qwhatsthis.h>
#include <qimage.h>
#include <qpixmap.h>
/*
 *  Constructs a dialogForm as a child of 'parent', with the
 *  name 'name' and widget flags set to 'f'.
 *
 *  The dialog will by default be modeless, unless you set 'modal' to
 *  TRUE to construct a modal dialog.
 */
dialogForm::dialogForm( QWidget* parent, const char* name, bool modal, WFlags fl )
    : QDialog( parent, name, modal, fl )
{
    if ( !name )
 setName( "dialogForm" );
    languageChange();
    resize( QSize(600, 480).expandedTo(minimumSizeHint()) );
    clearWState( WState_Polished );
}
/*
 *  Destroys the object and frees any allocated resources
 */
dialogForm::~dialogForm()
{
    // no need to delete child widgets, Qt does it all for us
}
/*
 *  Sets the strings of the subwidgets using the current
 *  language.
 */
void dialogForm::languageChange()
{
    setCaption( tr( "dialog Form" ) );
}

响应nextButton的函数放到了mainwinform.ui.h文件里面,如下
/****************************************************************************
** ui.h extension file, included from the uic-generated form implementation.
**
** If you want to add, delete, or rename functions or slots, use
** Qt Designer to update this file, preserving your code.
**
** You should not define a constructor or destructor in this file.
** Instead, write your code in functions called init() and destroy().
** These will automatically be called by the form's constructor and
** destructor.
*****************************************************************************/

void mainwinForm::on_nextButton_clicked()
{
     dg1form.show();
}

工程编译没有任何问题。 运行后按下next按钮, 什么反应也没有? 请大家指点一二。
如果使用QT4,很容易就实现了。 方法一样。
描述:工程源文件
附件: multiwingui.tar.bz2 (17 K) 下载次数:11
离线anthonymo200
只看该作者 1楼 发表于: 2010-11-09
问题解决了, 需要把on_nextButton_clicked()函数设置为SLOT函数, 然后连接一下信号就可以了。 感谢jetlee2012的关于Qt中界面跳转的问题的一些困扰,希望大家一起探讨一下文章。
离线dragonfever
只看该作者 2楼 发表于: 2011-04-16
回 楼主(anthonymo200) 的帖子
我是初学者,最近在作QT/E程序设计,参考了楼主的文,有些搞不懂上面程序中的dg1form是怎么用的?
离线angel0007

只看该作者 3楼 发表于: 2014-03-20
看看
hallo
快速回复
限100 字节
 
上一个 下一个