• 5442阅读
  • 0回复

请问大鸟们:qt2如何由按钮创建一个对话框啊?我用qwidgetfactory报错没有这个头文件 [复制链接]

上一主题 下一主题
离线xhyzjiji
 
只看楼主 倒序阅读 楼主  发表于: 2010-08-09
如题,头文件我找到了,在dqt目录下的include下,也加到Makefile了,后来编译后还是这个头文件里面用到的头文件出问题了(而且错误更多了,下面附图)。我是用qt designer做的对话框,主窗口就一个按钮,请问怎么在点击按钮后弹出这个对话框???谢谢。。。这个程序是准备移植到板子上的,555555弄了一个晚上都没结果。。。
  1. 这是disigner做的dialog的cpp文件,图片代码省略了
  2. #include "opendialog.h"
  3. #include <qiconview.h>
  4. #include <qpushbutton.h>
  5. #include <qlayout.h>
  6. #include <qvariant.h>
  7. #include <qtooltip.h>
  8. #include <qwhatsthis.h>
  9. #include <qimage.h>
  10. #include <qpixmap.h> 
  11. MyDialog::MyDialog( QWidget* parent,  const char* name, bool modal, WFlags fl )
  12.     : QDialog( parent, name, modal, fl )
  13. {
  14.     QPixmap image0( ( const char** ) image0_data );
  15.     if ( !name )
  16.  setName( "MyDialog" );
  17.     resize( 515, 286 );
  18.     setCaption( tr( "MyDialog" ) );
  19.     setSizeGripEnabled( TRUE );
  20.     QWidget* privateLayoutWidget = new QWidget( this, "Layout1" );
  21.     privateLayoutWidget->setGeometry( QRect( 20, 230, 476, 33 ) );
  22.     Layout1 = new QHBoxLayout( privateLayoutWidget );
  23.     Layout1->setSpacing( 6 );
  24.     Layout1->setMargin( 0 );
  25.     buttonHelp = new QPushButton( privateLayoutWidget, "buttonHelp" );
  26.     buttonHelp->setText( tr( "&Help" ) );
  27.     buttonHelp->setAutoDefault( TRUE );
  28.     Layout1->addWidget( buttonHelp );
  29.     QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
  30.     Layout1->addItem( spacer );
  31.     buttonApply = new QPushButton( privateLayoutWidget, "buttonApply" );
  32.     buttonApply->setText( tr( "&Apply" ) );
  33.     buttonApply->setAutoDefault( TRUE );
  34.     Layout1->addWidget( buttonApply );
  35.     buttonOk = new QPushButton( privateLayoutWidget, "buttonOk" );
  36.     buttonOk->setText( tr( "&OK" ) );
  37.     buttonOk->setAutoDefault( TRUE );
  38.     buttonOk->setDefault( TRUE );
  39.     Layout1->addWidget( buttonOk );
  40.     buttonCancel = new QPushButton( privateLayoutWidget, "buttonCancel" );
  41.     buttonCancel->setText( tr( "&Cancel" ) );
  42.     buttonCancel->setAutoDefault( TRUE );
  43.     Layout1->addWidget( buttonCancel );
  44.     IconView3 = new QIconView( this, "IconView3" );
  45.     (void) new QIconViewItem( IconView3, tr( "test.db" ), image0 );
  46.     IconView3->setGeometry( QRect( 30, 10, 441, 201 ) );
  47.     // signals and slots connections
  48.     connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( reject() ) );
  49.     connect( buttonHelp, SIGNAL( clicked() ), this, SLOT( helpme() ) );
  50.     connect( buttonApply, SIGNAL( clicked() ), this, SLOT( accept() ) );
  51.     connect( buttonOk, SIGNAL( clicked() ), this, SLOT( accept() ) );
  52.     connect( IconView3, SIGNAL( doubleClicked(QIconViewItem*) ), this, SLOT( openfile() ) );
  53. }
  54. /* 
  55.  *  Destroys the object and frees any allocated resources
  56.  */
  57. MyDialog::~MyDialog()
  58. {
  59.     // no need to delete child widgets, Qt does it all for us
  60. }
  61. void MyDialog::helpme()
  62. {
  63.     qWarning( "MyDialog::helpme(): Not implemented yet!" );
  64. }
  65. void MyDialog::selected()
  66. {
  67.     qWarning( "MyDialog::selected(): Not implemented yet!" );
  68. }
  69. void MyDialog::openfile()
  70. {
  71.     qWarning( "MyDialog::openfile(): Not implemented yet!" );
  72. }
  73. //这是只有一个按钮的主窗口cpp
  74. #include "previewbutton.h"
  75. #include "opendialog.h"
  76. #include "/opt/EmbedSky/Qte/x86-qtopia-2.2.0/dqt/include/qwidgetfactory.h"
  77. #include <qpushbutton.h>
  78. #include <qlayout.h>
  79. #include <qvariant.h>
  80. #include <qtooltip.h>
  81. #include <qwhatsthis.h>
  82. #include <qstring.h>
  83. #include <qfiledialog.h>
  84. //#include <qwidgetfactory.h>
  85. /*
  86.  *  Constructs a Form1 which is a child of 'parent', with the
  87.  *  name 'name' and widget flags set to 'f'
  88.  */
  89. Form1::Form1( QWidget* parent,  const char* name, WFlags fl )
  90.     : QWidget( parent, name, fl )
  91. {
  92.     if ( !name )
  93.  setName( "Form1" );
  94.     resize( 596, 480 );
  95.     setCaption( tr( "Form1" ) );
  96.     open_file = new QPushButton( this, "open_file" );
  97.     open_file->setGeometry( QRect( 310, 10, 91, 41 ) );
  98.     open_file->setText( tr( "Openfile" ) );
  99.     // signals and slots connections
  100.     connect( open_file, SIGNAL( clicked() ), this, SLOT( tofile() ) );
  101. }
  102. /* 
  103.  *  Destroys the object and frees any allocated resources
  104.  */
  105. Form1::~Form1()
  106. {
  107.     // no need to delete child widgets, Qt does it all for us
  108. }
  109. void Form1::tofile()
  110. {
  111. //    qWarning( "Form1::tofile(): Not implemented yet!" );
  112.     MyDialog* openfiledia = ( MyDialog* ) QWidgetFactory::create( "opendialog.ui" );
  113.     openfiledia->exec();
  114. }

谢谢大虾们了,我是初学的,很多不懂。。。
快速回复
限100 字节
 
上一个 下一个