1

この致命的なエラーは、Macintosh で実行した場合にのみ発生しますが、Windows ブラウザーでは発生しません。これは、ブラウザーの状態をチェックする以外に、条件付きループが同じコードを実行するため、意味がありません。

PHPでこのエラーを停止する方法を誰かが理解するのを手伝ってくれますか? エラーは QEnterKeyEvent の最初のインスタンスで発生します... 2 番目ではありません。これは意味がありません。

コードでは、最初のインスタンスが呼び出されるのは初めてなので、私が知る限り、クラスはまだ作成されていません。

それでもエラーは言う:クラスQEnterKeyEventを再宣言することはできません

// Key-Specific Events (EnterKey, EscapeKey, UpArrowKey, DownArrowKey, etc.)

if (QApplication::IsBrowser(QBrowserType::Macintosh)) {
    echo "keyspecific events - macintosh";

    class QEnterKeyEvent extends QKeyPressEvent {
        protected $strCondition = 'event.keyCode == 13';
    }
    class QEscapeKeyEvent extends QKeyPressEvent {
        protected $strCondition = 'event.keyCode == 27';
    }
    class QUpArrowKeyEvent extends QKeyPressEvent {
        protected $strCondition = 'event.keyCode == 38';
    }
    class QDownArrowKeyEvent extends QKeyPressEvent {
        protected $strCondition = 'event.keyCode == 40';
    }
} else {
    echo "key specific events - windows";

    class QEnterKeyEvent extends QKeyDownEvent {
        protected $strCondition = 'event.keyCode == 13';
    }
    class QEscapeKeyEvent extends QKeyDownEvent {
        protected $strCondition = 'event.keyCode == 27';
    }
    class QUpArrowKeyEvent extends QKeyDownEvent {
        protected $strCondition = 'event.keyCode == 38';
    }
    class QDownArrowKeyEvent extends QKeyDownEvent {
        protected $strCondition = 'event.keyCode == 40';
    }
}
4

4 に答える 4

1

このコード サンプルは QCodo コードベースのものだと思いますか? その場合、おそらく「バグと問題」フォーラムを通じて問題を報告する必要があります。そこを見てみると、すでにいくつかのレポートがあることがわかります。これこれ...

完全なコード ブロックは次のとおりです (Qcodo サイトのフォーラム投稿から)。

// Key-Specific Events (EnterKey, EscapeKey, UpArrowKey, DownArrowKey, etc.)

if (QApplication::IsBrowser(QBrowserType::Macintosh)) {
    class QEnterKeyEvent extends QKeyPressEvent {
        protected $strCondition = 'event.keyCode == 13';
    }
    class QEscapeKeyEvent extends QKeyPressEvent {
        protected $strCondition = 'event.keyCode == 27';
    }
    class QUpArrowKeyEvent extends QKeyPressEvent {
        protected $strCondition = 'event.keyCode == 38';
    }
    class QDownArrowKeyEvent extends QKeyPressEvent {
        protected $strCondition = 'event.keyCode == 40';
    }
} else {
    class QEnterKeyEvent extends QKeyDownEvent {
        protected $strCondition = 'event.keyCode == 13';
    }
    class QEscapeKeyEvent extends QKeyDownEvent {
        protected $strCondition = 'event.keyCode == 27';
    }
    class QUpArrowKeyEvent extends QKeyDownEvent {
        protected $strCondition = 'event.keyCode == 38';
    }
    class QDownArrowKeyEvent extends QKeyDownEvent {
        protected $strCondition = 'event.keyCode == 40';
    }
} 

したがって、2 回目の読み取りでは、問題はこのコード ブロックが両方のクラス定義にヒットすることではなく、このコード ブロックが実際に 2 回呼び出されることだと思います。Qcodo を 2 回初期化すると、(Qcodo を一目見ただけで) これが発生するように見えます。

QApplicationBase::Initialize() には、次のコードがあります。

  // Preload Class Files
  foreach (QApplication::$PreloadedClassFile as $strClassFile)
      require($strClassFile);

それを以下のコードに置き換えてみて、問題が解決するかどうかを確認してください。その場合、Qcodo をコードのどこかで誤って 2 回初期化した可能性があります。

  // Preload Class Files
  foreach (QApplication::$PreloadedClassFile as $strClassFile)
      require_once($strClassFile);
于 2009-01-06T08:41:19.623 に答える
0

XSilvaのLightspeedWebstoreをクライアントにインストールしようとしたときに、この同じ問題が発生しました。いくつか掘り下げてテストした後、私は問題を解決したと思います。(参考までに、「require」を「require_once」に変更するだけではうまくいきませんでした。)これは醜いハックだと思いますが、問題のあるコードブロックをclass_exists()チェックで次のようにラップしました。

// Key-Specific Events (EnterKey, EscapeKey, UpArrowKey, DownArrowKey, etc.)
if (QApplication::IsBrowser(QBrowserType::Macintosh)) {
    if(!class_exists('QEnterKeyEvent') and !class_exists('QEscapeKeyEvent') and !class_exists('QUpArrowKeyEvent') and !class_exists('QDownArrowKeyEvent')) {
        class QEnterKeyEvent extends QKeyPressEvent {
            protected $strCondition = 'event.keyCode == 13';
        }   
        class QEscapeKeyEvent extends QKeyPressEvent {
            protected $strCondition = 'event.keyCode == 27';
        }   
        class QUpArrowKeyEvent extends QKeyPressEvent {
            protected $strCondition = 'event.keyCode == 38';
        }   
        class QDownArrowKeyEvent extends QKeyPressEvent {
            protected $strCondition = 'event.keyCode == 40';
        }   
    }   
} else {
    class QEnterKeyEvent extends QKeyDownEvent {
        protected $strCondition = 'event.keyCode == 13';
    }   
    class QEscapeKeyEvent extends QKeyDownEvent {
        protected $strCondition = 'event.keyCode == 27';
    }   
    class QUpArrowKeyEvent extends QKeyDownEvent {
        protected $strCondition = 'event.keyCode == 38';
    }   
    class QDownArrowKeyEvent extends QKeyDownEvent {
        protected $strCondition = 'event.keyCode == 40';
    }   
}   
于 2010-01-09T17:33:28.077 に答える
0

QCubed と呼ばれる QCodo のコミュニティ ブランチがあり、現在 QA で修正されているようです。 http://trac.qcu.be/projects/qcubed/ticket/134

于 2010-02-02T20:32:33.103 に答える
0

どちらのコード ブロックも同じクラスを定義します。

class QEnterKeyEvent extends QKeyDownEvent {
            protected $strCondition = 'event.keyCode == 13';
}

あなたが提供するサンプルコードから、そのクラスを if / else ステートメントの外側で完全に定義する方が理にかなっています。これにより、維持するコードの量が削減され、エラーが解決されます。

ただし、コードを読むときに中括弧が一致していないのではないかと思います。貼り付けるときにスニペットから、エラーは発生しません。

2 番目のクラス定義が最初のクラス定義と同じように発生している場合 (それらは同じ条件の一部ではないため)、そのエラーが表示されることが予想されます。

重複を避けるためにコードを再構築しないことに決めた場合 (現在の構造には正当な理由があり、与えられたスニペットに示されていないものがあるかもしれません)、PHP のclass_exists()を使用して、クラスを複製しようとする試みを避けることができます。意味:

} else {
  if ( !class_exists('QEnterKeyEvent') ) {
    class QEnterKeyEvent extends QKeyDownEvent {
      protected $strCondition = 'event.keyCode == 13';
    }
  }
}

このアプローチを使用する場合は、すべてのケースで期待どおりにクラスが定義されていることを注意深く確認することをお勧めします。

PS。このコード サンプルは QCodo コードベースからのものですか? もしそうなら、おそらく「バグと問題」フォーラムを通じて問題を報告する必要があります。

PPS。ほら見て。これこれを見て...

于 2009-01-06T00:59:38.260 に答える