簡體   English   中英

QmodelIndex和標頭數據

[英]QmodelIndex and header data

我的ui屏幕中有4個tableviews。在我的4個視圖的header數據函數中,我只需要一個1行名稱-用於視圖1和3的溫度以及四行名稱字段分別為1x,4x,10x和40x 。 我的功能是

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,我不會

請幫忙

您在switch語句中缺少中斷。 例如:

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

通常,為switch語句提供default標簽也是一個好主意。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM