1

Qt で opencv を使用して、論文のビデオ認識を行っています。

だから私はメインウィンドウ(カメラとカメラの設定用のいくつかのスライダーを表示する)と、高度な設定用のスライダー付きのボタンを押すと開くダイアログウィンドウを持っています。私の問題は次のとおりです。次のようなクラスのインスタンスで作成します

Moving M; 

mainwindow.cpp で、次のようなパラメーターを設定できます

M.BasicSetting1 = someValue; 

しかし、別のウィンドウ (ダイアログ) で M インスタンスにアクセスして、M.AdvencedSettings を設定することはできません。

では、mainwindow.cpp と dialog.cpp の両方でパラメーターを設定するには、Moving クラスのインスタンスをどこでどのように作成する必要があるのでしょうか? 私が十分に明確であったことを願っています...おそらく、誰かがその方法のさまざまな単純な例を投稿できれば。大変お世話になりました!


これが私が持っているものです(この方法で簡単になるので、完全なコードを投稿するつもりはありません(私がする必要がないことを願っています:))

Moving.h        //where my class is defined which accesses my webcam and stuff
mainwindow.h    //mainwindow where it shows the video with basicsettings
dialog.h        //some advanced settings for the webcam

main.cpp         
Moving.cpp
Mainwindow.cpp    
dialog.cpp

動く.h

        class Moving
    {

    public:

int BasicSetting1;
int Basic Setting2;

int AdvancedSetting1;
int AdvancedSetting2;

    //lots of other stuff

    Moving();
    ~Moving();

    void move();  //starts and shows the camera

    };

メインウィンドウ.cpp

      #include "Moving.h"
      #include "mainwindow.h"


        Moving M;

        M.BasicSetting1 = SliderValue; 

        M.move();  //shows camera



    //and of course lots of other stuff
4

1 に答える 1

4

If I read your code correctly then you are creating the instance of Moving on the stack. Sharing pointers or references to stack objects can be dangerous. Instead you could declare Moving in your mainwindow and add a getter type method (i.e. Moving* getMoving()) to return an pointer to your Moving object. Then give your Dialog a pointer to the mainwindow.

All of this is very basic to the concept of programming. Maybe you should read some tutorials and do some other smaller stuff before writing your thesis; patching bad code can be very time-consuming.

于 2012-12-06T11:47:57.860 に答える