0

UI画面に4つのテーブルビューがあります.4つのビューのヘッダーデータ関数では、ビュー1と3の1行の名前-温度と、それぞれ名前フィールド1x、フィールド4x、フィールド10x、フィールド40xの4つの行が必要です. 私の機能は

virtual QVariant headerData(int section,Qt::Orientation orientation,
                int role = Qt::DisplayRole) const
    {
        switch(role)
        {
        case Qt::DisplayRole:
            switch (orientation)
            {
            case Qt::Vertical:
 switch (m_channel)
                    {
                    case 0:
                        switch (section)    // Range
                        {
                        case 0:
                            return "Temperature1";
                        }
                    case 1:
                        switch (section)    // Range
                        {
                        case 0:
                            return "Field 1x range";
                        case 1:
                            return "Field 4x range";
                        case 2:
                            return "Field 10x range";
                        case 3:
                            return "Field 40x range";
                        }
                    case 2:
                        switch (section)    // Range
                        {
                        case 0:
                            return "Temperature2";
                        }
                    case 3:
                        switch (section)    // Range
                        {
                        case 0:
                            return "Field 1x range";
                        case 1:
                            return "Field 4x range";
                        case 2:
                            return "Field 10x range";
                        case 3:
                            return "Field 40x range";
                        }

しかし、コンパイル時の画面には、ビュー 1 とビュー 3 の温度、フィールド 4x、フィールド 10x、フィールド 40x が表示されます。

助けてください

4

1 に答える 1

0

switchステートメントに区切りがありません。例えば:

                    switch (m_channel)
                    {
                    case 0:
                        switch (section)    // Range
                        {
                        case 0:
                            return "Temperature1";
                        }
                        break; // <-- You need this.
                    case 1:
                        ...

また、ステートメントにdefaultラベルを付けるのも一般的には良い考えです。switch

于 2013-07-26T17:50:00.310 に答える