• 4535阅读
  • 1回复

两个窗口切换问题 [复制链接]

上一主题 下一主题
离线leeqm
 
只看楼主 倒序阅读 楼主  发表于: 2008-07-29
— 本帖被 XChinux 执行加亮操作(2008-07-29) —
qt的一个form1中的button被push后,怎么把它connect连接到另外一个form2,显示form2而不显示form1.
以下程序编译后会有Form2及其函数没有声明的错误,请问为什么?


#include <qapplication.h>
#include <qpushbutton.h>

#include <qfont.h>
#include <qdialog.h>



class Form1 : public QDialog
{
public:
    Form1 ( QWidget *parent=0, const char *name=0 );
    Form2 *Form2;
};


Form1::Form1( QWidget *parent, const char *name )
        : QDialog( parent, name )
{
   
   
QPushButton *next = new QPushButton( "Next", this, "quit" );
    next->setFont( QFont( "Times", 18, QFont::Bold ) );
    Form2=new Form2(this);
    connect( next, SIGNAL(clicked()), Form2, (form2_slot_name()) );

 
}

class Form2 : public QDialog
{
public:
    Form2 ( QWidget *parent=0, const char *name=0 );
};

Form2::Form2( QWidget *parent, const char *name )
        : QDialog( parent, name )
{

public:

  Form1 *f1;
  QPushButton *next2 = new QPushButton( "Next2", this, "quit" );
    next2->setFont( QFont( "Times", 18, QFont::Bold ) );

    f1=new Form1(this);
  void form2_slot_name();
 
}

void Form2::form2_slot_name()
{
if(f1->isShown())
f1->hide();

show();
}




int main( int argc, char **argv )
{
    QApplication a( argc, argv );

    Form1 w;
    a.setMainWidget( &w );
    w.show();
    return a.exec();
}
离线xjcook

只看该作者 1楼 发表于: 2008-07-29
编译器报的没有错误,因为你的form2放在form1的下面,编译from1的时候form2还没有被认识。
你在.h前面加上两句
class Form1;
class Form2;
然后把实现代码放到CPP里就可以了
快速回复
限100 字节
 
上一个 下一个