2012-04-21 94 views
-1

請幫我解釋意外的崩潰!!! 我:QT 4.8普通比較崩潰

x.h

class x: QObject 
    struct 
    { 
     struct 
     { 
      struct 
      { 
       int state; 
       double curstring; 
       QTimer timer_scroll; 
       QTimer timer_done; 
      }color; 
      struct 
      { 
       int state; 
       double curstring; 
       QTimer timer_scroll; 
       QTimer timer_done; 
      }mono; 
     }S2L_NOTIFY; 

....等

x.cpp

void x::draw(const int type, QString str, bool isNeedAnswer) 
{ 
    if(type == 3) 
    { 
     //here is crash! 
     if(bitmap.S2L_NOTIFY.mono.state == 3 && bitmap.S2L_NOTIFY.color.state == 3) 
     { 

if((bitmap.S2L_NOTIFY.mono.state == 3)) - <不會崩潰這裏

if((bitmap.S2L_NOTIFY.color.state == 3)) - <不會崩潰這裏

請告訴我,我錯了或compilator錯了嗎?

+2

可以運行在'valgrind'或其他一些調試你的程序? – sarnold 2012-04-21 00:45:21

+1

你至少應該發佈一個編譯代碼..你提供的是foobar。 – 2012-04-21 01:09:42

回答

1

的問題是,你有你的條件X1,但功能x::rndfunc()是類X的成員函數...不是一個變量。它應該是:

// "this" refers to the current instance of class x 
if((this->y.z.f.nmb2 == NOTOK) && (this->y.z.f.nmb1 == NOTOK)) 

或者乾脆:

// but the "this" isn't actually necessary 
if((y.z.f.nmb2 == NOTOK) && (y.z.f.nmb1 == NOTOK)) 

(爲你寫)。

編輯:好的,所以原來的問題有一個錯字,所以上面的不再相關。新的答案是:

f沒有成員變量nmb1,只有nmb2

編輯#2:更多錯別字。我的新的答案:

你想要做什麼看起來很凌亂。不要這樣做。

+0

如果((這個 - > y.z.f.nmb2 == NOTOK)&&(這個 - > y.z.f.nmb1 == NOTOK)) 這是我的筆誤,還是PROGRAMM多年平均值的工作。 – HARD 2012-04-21 01:03:36

+1

@HARD那麼不是nmb1不是f的成員變量(而是h)的問題? – Anthony 2012-04-21 01:11:56

+0

不,我肯定是99% – HARD 2012-04-21 02:07:33