• 6934阅读
  • 5回复

VS2010在调试QT的工程文件时遇到的问题 [复制链接]

上一主题 下一主题
离线暴风影音
 
只看楼主 倒序阅读 楼主  发表于: 2013-03-11
关键词: 求助
VS2010在调试QT的工程文件时遇到的问题,求指教!不慎感激。。。
离线realfan

只看该作者 1楼 发表于: 2013-03-12
提示Vector越界,先检查一下自己的代码
离线暴风影音
只看该作者 2楼 发表于: 2013-03-12
#include"QtGui"
#include "histogram.h"

HistogramWidget::HistogramWidget(QWidget *parent) :
    QWidget(parent)
{
    m_BKColor = QColor( 255,255,255 );
    m_VecPixmap.clear( );//清空堆栈

    setAutoFillBackground( true );
    setPalette( QPalette( m_BKColor ) );
    setMinimumSize( 320, 240 );
    adjustSize( );
}
void HistogramWidget::AddItem(QString name, quint32 value, QColor pillarColor)
{
  HistogramItem item;
  item.m_pillarName=name;
  item.m_pillarValue=value;
  item.m_pillarColor=pillarColor;
  item.m_pillarRect=QRect();
  m_VecItems.push_back( item );//把以上四项载入头文件中已声明的容积
}
void HistogramWidget::SetMaxValue(quint32 maxValue)
{
  m_MaxValue=maxValue;//给y轴设置最大值,也即是给柱状图设置最大值
}
void HistogramWidget::paintEvent(QPaintEvent *)
{
    QPainter painter(this);
    DrawAxis(&painter);
    DrawPillar(&painter);
    DrawText(&painter);
    DrawScale(&painter);
    QFont font;//设置窗口部件的字体//
    font.setPointSize(8);
    setFont(font);//选择字体//
}
void HistogramWidget::DrawAxis(QPainter *painter)//绘制坐标轴
{
    painter->drawLine(xAxisOffset,yAxisOffset,xAxisOffset,height());//绘制y轴
    painter->drawLine(xAxisOffset,yAxisOffset,width(),yAxisOffset);//绘制x轴
}
void HistogramWidget::DrawPillar(QPainter *painter)//绘制柱子
{
    if(m_VecItems.size()==0)return;//容积内没有封装任何东西返回
    const quint32 blankWidth=0;
    quint32 pillarWidth=(width()-xAxisOffset-pillarIndent)/12;//每个柱子的宽度
    int m_MaxValue = 10;
    float heightFact=(float)(height()-yAxisOffset)/(m_MaxValue);
    for(int i=0;i<12;++i)
    {
        quint32 pillarHeight=m_VecItems.m_pillarValue*heightFact;
        int leftUpX=xAxisOffset+pillarIndent+i*(pillarWidth+blankWidth);
        int leftUpY=height()-yAxisOffset-pillarHeight;
        QRect &rect=m_VecItems.m_pillarRect;
        rect.setRect(leftUpX,leftUpY,pillarWidth,pillarHeight);//绘制柱状图
        painter->setPen(QPen(m_VecItems.m_pillarColor));//为第i个柱状图设置颜色
        painter->drawRect(rect);//在绘图版上进行绘图
    }
}
void HistogramWidget::DrawText(QPainter *painter)//绘制文字
{
    painter->setPen(QPen(QColor(0,0,0)));
    for(int i=0;i<12;++i)
    {
        QRect rect(m_VecItems.m_pillarRect.left()-blankWidth/2,m_VecItems.m_pillarRect.top()-textRectHeight,
                   m_VecItems.m_pillarRect.width(),textRectHeight);
        const QString &text=QString( "%1(%2)" ).arg( m_VecItems.m_pillarName).arg( m_VecItems.m_pillarValue);
        painter->drawText(rect,Qt::AlignVCenter | Qt::AlignBottom,text);
    }
}
void HistogramWidget::DrawScale(QPainter *painter)//为坐标组绘制刻度
{
    const quint32 MSWidth=100;//为横轴设置刻度宽
    const quint32 MSHeight=textRectHeight;//为纵轴设置刻度宽
    const quint32 heightInterval=(height()-yAxisOffset)/10;
for(int i=0;i<10;++i)//y轴画刻度及标度刻度值
{
    QRect rect(0,i*heightInterval,MSWidth,MSHeight);
    painter->setPen(Qt::black);
    painter->drawLine(yAxisOffset-2,i*heightInterval,yAxisOffset+2,i*heightInterval);//画刻度
    painter->drawText(rect,Qt::AlignLeft,QString("%1").arg(m_MaxValue*(10-i)/10));//标记刻度值

}
for (int i = 1; i <= 12; ++i)//x轴画刻度
{
painter->setPen(Qt::black);
painter->drawLine(MSWidth * i,xAxisOffset-2,MSWidth* i, xAxisOffset+2);
}
}
void HistogramWidget ::DrawPixmaps( )
{
    m_VecPixmap.clear( );
    QPixmap pixmap( minimumSize( ) * 0.8 );//像素映射的大小调整为窗口闩大小的80%
    pixmap.fill( QColor( 255, 255, 255 ) );//使用白色填充像素映射
    m_VecPixmap.push_back( pixmap );

    // 绘制一张像素图
    HistogramWidget histogram;
    histogram.SetMaxValue( 1000 );
    histogram.AddItem( tr( "1" ), 100, QColor( 125, 0, 0 ) );
    histogram.AddItem( tr( "2" ), 150, QColor( 0, 125, 0 ) );
    histogram.AddItem( tr( "3" ), 200, QColor( 0, 0, 125 ) );
    histogram.AddItem( tr( "4" ), 250, QColor( 125, 125, 125 ));
    histogram.AddItem( tr( "5" ), 300, QColor( 125, 0, 0 ) );
    histogram.AddItem( tr( "6" ), 350, QColor( 0, 125, 0 ) );
    histogram.AddItem( tr( "7" ), 400, QColor( 0, 0, 125 ) );
    histogram.AddItem( tr( "8" ), 450, QColor( 125, 125, 125 ));
    histogram.AddItem( tr( "9" ), 500, QColor( 125, 0, 0 ) );
    histogram.AddItem( tr( "10" ),750, QColor( 0, 125, 0 ) );
    histogram.AddItem( tr( "11" ),800, QColor( 0, 0, 125 ) );
    histogram.AddItem( tr( "12" ),950, QColor( 125, 125, 125 ));
    QPainter painter(&pixmap);
    painter.initFrom(this);//调用之前设置的画笔.背景及其字体
   DrawPillar(&painter);//载入数据在窗口部件上执行绘图操作;
}
    以上是我的.cpp文件的代码,望指正代码错误。
离线realfan

只看该作者 3楼 发表于: 2013-03-12
m_VecItems是QVector吗?
m_VecItems.m_pillarValue这样的用法,我还真没见过。能编译过吗?
离线XChinux

只看该作者 4楼 发表于: 2013-03-13
引用第3楼realfan于2013-03-12 11:57发表的  :
m_VecItems是QVector吗?
m_VecItems.m_pillarValue这样的用法,我还真没见过。能编译过吗?


realfan有兴趣参与qtcn.org管理或开发么?(你的站内信箱满了)
二笔 openSUSE Vim N9 BB10 XChinux@163.com 网易博客 腾讯微博
承接C++/Qt、Qt UI界面、PHP及预算报销系统开发业务
离线暴风影音
只看该作者 5楼 发表于: 2013-03-13
可以编译过的,确实是向量越界问题的。。。。
快速回复
限100 字节
 
上一个 下一个