• 4683阅读
  • 4回复

QT界面跳转的问题 急急急急!!! [复制链接]

上一主题 下一主题
离线jxq19881013
 

只看楼主 倒序阅读 楼主  发表于: 2009-05-22
我使用的是QT版本是QT-2.3.7,出现的问题是第二个窗体不能显示出来!!!
具体的代码如下:
/****************************Main.cpp*********************************************/
#include <qapplication.h>
#include "formtest.h"

int main( int argc, char ** argv )
{
    QApplication app( argc, argv );
    First formTest;
    app.setMainWidget(&formTest);
    formTest.show();
    return app.exec();
}
/*第一个窗体的文件******************************************************************/
          /******************formtest.h***********************/
/****************************************************************************
** Form interface generated from reading ui file 'formtest.ui'
**
** Created: Thu May 21 20:30:55 2009
**      by:  The User Interface Compiler (uic)
**
** WARNING! All changes made in this file will be lost!
****************************************************************************/
#ifndef FIRST_H
#define FIRST_H

#include <qvariant.h>
#include <qwidget.h>
#include "./formtest2.h"

class QVBoxLayout;
class QHBoxLayout;
class QGridLayout;
class QPushButton;
class SecondForm;

class First : public QWidget
{
    Q_OBJECT

public:
    First( QWidget* parent = 0, const char* name = 0, WFlags fl = 0 );
    ~First();
    
    QPushButton* OKButton;
    SecondForm secondForm;
private slots:
    void displayForm2( );

};

#endif // FIRST_H
/**************formtest.cpp************************/
/****************************************************************************
** Form implementation generated from reading ui file 'formtest.ui'
**
** Created: Thu May 21 20:31:05 2009
**      by:  The User Interface Compiler (uic)
**
** WARNING! All changes made in this file will be lost!
****************************************************************************/
#include "formtest.h"

#include <qpushbutton.h>
#include <qlayout.h>
#include <qvariant.h>
#include <qtooltip.h>
#include <qwhatsthis.h>

/*
*  Constructs a First which is a child of 'parent', with the
*  name 'name' and widget flags set to 'f'
*/
First::First( QWidget* parent,  const char* name, WFlags fl )
    : QWidget( parent, name, fl )
{
    if ( !name )
setName( "First" );
    resize( 400, 400 );
    setMaximumSize( QSize( 400, 400 ) );
    setCaption( tr( "first" ) );

    OKButton = new QPushButton( this, "OKButton" );
    OKButton->setGeometry( QRect( 140, 70, 70, 40 ) );
    OKButton->setText( tr( "OK" ) );

  
    connect(OKButton, SIGNAL( clicked() ), this, SLOT( displayForm2( ) ) );
  
}

/*  
*  Destroys the object and frees any allocated resources
*/
First::~First()
{
    // no need to delete child widgets, Qt does it all for us
}

void First::displayForm2( )

{



  this->close();
  secondForm.show();
                      
}


/*第二个窗体的文件************************************************************/

/***********************************formtest2.h****************************************/
/****************************************************************************
** Form interface generated from reading ui file 'formtest2.ui'
**
** Created: Thu May 21 20:31:18 2009
**      by:  The User Interface Compiler (uic)
**
** WARNING! All changes made in this file will be lost!
****************************************************************************/
#ifndef SECONDFORM_H
#define SECONDFORM_H

#include <qvariant.h>
#include <qwidget.h>
class QVBoxLayout;
class QHBoxLayout;
class QGridLayout;
class QTextBrowser;

class SecondForm : public QWidget
{
    Q_OBJECT

public:
    SecondForm( QWidget* parent = 0, const char* name = 0, WFlags fl = 0 );
    ~SecondForm();

    QTextBrowser* TextBrowser1;

};

#endif // SECONDFORM_H

/****************************************formtest2.cpp********************************/
/****************************************************************************
** Form implementation generated from reading ui file 'formtest.ui'
**
** Created: Thu May 21 20:31:05 2009
**      by:  The User Interface Compiler (uic)
**
** WARNING! All changes made in this file will be lost!
****************************************************************************/
#include "formtest.h"

#include <qpushbutton.h>
#include <qlayout.h>
#include <qvariant.h>
#include <qtooltip.h>
#include <qwhatsthis.h>

/*
*  Constructs a First which is a child of 'parent', with the
*  name 'name' and widget flags set to 'f'
*/
First::First( QWidget* parent,  const char* name, WFlags fl )
    : QWidget( parent, name, fl )
{
    if ( !name )
setName( "First" );
    resize( 400, 400 );
    setMaximumSize( QSize( 400, 400 ) );
    setCaption( tr( "first" ) );

    OKButton = new QPushButton( this, "OKButton" );
    OKButton->setGeometry( QRect( 140, 70, 70, 40 ) );
    OKButton->setText( tr( "OK" ) );

  
    connect(OKButton, SIGNAL( clicked() ), this, SLOT( displayForm2( ) ) );
  
}

/*  
*  Destroys the object and frees any allocated resources
*/
First::~First()
{
    // no need to delete child widgets, Qt does it all for us
}

void First::displayForm2( )

{



  this->close();
  secondForm.show();
                      
}
离线jzj139
只看该作者 1楼 发表于: 2009-05-23
简单看了下,你这代码乱七八糟的。。。。。
在你显示第二个窗口的slot函数中把this->close()去掉
qt
离线jxq19881013

只看该作者 2楼 发表于: 2009-05-23
这个问题已经解决,问题在一定要把那个显示的窗体定义为指针类型,但我不能理解为什么会是这样.
请高手帮忙解答一下!
离线jzj139
只看该作者 3楼 发表于: 2009-05-23
你要显示这个窗体应该是要在内存中的,然后映射到framebuffer来显示。
qt
离线jxq19881013

只看该作者 4楼 发表于: 2009-05-23
理解了,谢谢了!请帮忙看下我的另外一个帖子,关于图像处理方面的。
快速回复
限100 字节
 
上一个 下一个