QmodelIndex和标头数据

时间:2013-07-26 15:51:23

标签: c++ qt user-interface qt-creator

我的ui屏幕上有4个tableviews。在我的4个视图的标题数据函数中,我只需要一个1行名称 - 温度用于视图1和3和4行,名称字段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";
                        }

但是,编译时的屏幕显示温度,字段4x,字段10x,视图1和视图3的字段40x,我不会

请帮忙

1 个答案:

答案 0 :(得分:0)

您在switch声明中遗漏了休息时间。例如:

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

default语句提供switch标签通常也是一个好主意。