• 5894阅读
  • 4回复

问一个比较幼稚的问题 [复制链接]

上一主题 下一主题
离线crespo102418
 
只看楼主 倒序阅读 楼主  发表于: 2007-02-06

我定义了一个class Video,由于其他的一些因素,我只能在main函数中Video *video=new Video;

现在我想在其他的函数中使用*video,我该怎么办?

谢谢大家帮帮我!

离线浪漫天使
只看该作者 1楼 发表于: 2007-02-06
大概的思路吧

extern Video *video;

int main(int argc,char *argv[])
{
…………
  Video *viewo = new Video;
…………
}

或者 把 *viewo 定义成全局变量,反正就那个意思吧。
离线crespo102418
只看该作者 2楼 发表于: 2007-02-07
不行啊,还是说子函数的video没有定义
离线浪漫天使
只看该作者 3楼 发表于: 2007-02-08

qt422,g++,windows 编译通过,只是涉及到编译,功能方面的问题没有测试,因为只想表达一个思路。

vedio.h

  1. #include <QtGui/QWidget>

    class VideoWgt : public QWidget

  2. {
  3. public:
  4.  VideoWgt(QWidget *parent = 0):QWidget(parent)
  5.  {
  6.   ;
  7.  }
  8.  ~VideoWgt(){;}
  9. };

another.h

  1. class Another
  2. {
  3. public:
  4.  Another(){;}
  5.  ~Another(){;}
  6. public:
  7.  void func();
  8. };

another.cpp

  1. #include "another.h"
  2. #include "vedio.h"

    extern VideoWgt *dlg;

    void Another::func()

  3. {
  4.  dlg->setWindowTitle("hah");
  5. }

     

main.cpp

  1. #include "vedio.h"

    #include <QtGui/QApplication>

    VideoWgt *dlg;

    int main(int argc, char *argv[])

  2. {
  3.     QApplication app(argc,argv);

        dlg = new VideoWgt();

  4.    
  5.     dlg->show();

     app.connect(&app,SIGNAL(lastWindowClosed()),&app,SLOT(quit()));

  6.     return app.exec();
  7. }

附件上传不了…………

离线myer

只看该作者 4楼 发表于: 2007-02-12
extern当然可以,但是不太好维护
你可以将Video *指针作为需要它的类的构造函数的一个参数,当然也可以实现一个setVideo(Video *)函数。
http://user.qzone.qq.com/56430808
快速回复
限100 字节
 
上一个 下一个