• 10254阅读
  • 5回复

【提问】qt 与单例模式 [复制链接]

上一主题 下一主题
离线king_xl
 

只看楼主 倒序阅读 楼主  发表于: 2006-03-15
qt到底能不能用单例模式啊,怎么我用了好像连main函数都进不去了呢,编译可通过但运行没反应,tx们过来看一看,需要的话我可以贴代码出来。
[ 此贴被XChinux在2006-03-15 15:29重新编辑 ]
离线XChinux

只看该作者 1楼 发表于: 2006-03-15
何谓“单例”模式?
二笔 openSUSE Vim N9 BB10 XChinux@163.com 网易博客 腾讯微博
承接C++/Qt、Qt UI界面、PHP及预算报销系统开发业务
离线king_xl

只看该作者 2楼 发表于: 2006-03-15
我把代码贴出来吧,帮我看看。

//头文件 omainframe.h

#ifndef OMAINFRAME_H
#define OMAINFRAME_H

//#include <qmotifdialog.h>
#include <qwidget.h>
#include <qdialog.h>

class QLabel;
class QPushButton;

class OMainFrame : public QDialog
{
  Q_OBJECT

private:
  OMainFrame( QWidget*parent = 0, const char *name = 0,
            bool modal = FALSE, WFlags flags = 0 );
  OMainFrame();
public:
  ~OMainFrame();

private:
     static OMainFrame *mainframe;

  QPushButton *testBtn;    

public:
     static OMainFrame *getMainframe();
     
public slots:
};

#endif // OMAINFRAME_H


//源文件 omainframe.cpp
#include <qpushbutton.h>
#include "include/omainframe.h"

OMainFrame * OMainFrame::mainframe = new OMainFrame( 0, "optface", FALSE , 0x00001000);

OMainFrame::OMainFrame( QWidget *parent, const char *name, bool modal, WFlags flags )
  : QDialog( parent, name, modal, flags )
{      
  testBtn = new QPushButton(this);

  connect(testBtn, SIGNAL(clicked()), this, SLOT(close()));
}

OMainFrame::~OMainFrame()
{
}


OMainFrame *OMainFrame::getMainframe()
{
     return OMainFrame::mainframe;
}


//main.cpp
#include <qapplication.h>
#include "include/omainframe.h"
#include <qmessagebox.h>
#include <qtextcodec.h>

int main( int argc, char **argv )
{
  QApplication a(argc,argv);
     a.setDefaultCodec( QTextCodec::codecForName("GBK") );
  OMainFrame *h = OMainFrame::getMainframe();
  //OMainFrame *h = new OMainFrame;
  a.setMainWidget( h );

     QObject::connect( h, SIGNAL(lastWindowClosed()), &a, SLOT(quit()) );
  h->show();
 
  return a.exec();
}


能编译通过,但运行不了,好像连main函数都没进
离线wylhistory
只看该作者 3楼 发表于: 2006-03-16
不知道,介意,可以用gdb 跟踪一下,看到了什么地方,只要编译通过了应该很好查出问题,断点+print+where+up
离线king_xl

只看该作者 4楼 发表于: 2006-03-16
我用vc调试,根本就进不去main函数里,不知道为什么
离线giscn
只看该作者 5楼 发表于: 2006-03-17
qt 4 solutions有single app的实现方案,
http://nzt.spaces.live.com
快速回复
限100 字节
 
上一个 下一个