使用 QVector 创建图形磁贴(QCache 之前的基础知识)
Creating Graphics Tiles Using QVector(Basics Before QCache)
我正在尝试升级我的地震图查看器以使用磁贴图形渲染。我对这个过程非常陌生,但我尝试创建一个简单的例子如下。我需要使用 QVector 或 QCache(为了简单起见,我现在使用 QVector 的原因是为了节省内存和需要即时创建的瓷砖。我不完全确定你是否能够做我在下面尝试做的事情,但本质上它会创建一个位图数组,使它们成为项目,然后尝试将它们添加到场景中。该程序编译时有十二个错误,没有一个直接引用我在 mainWindow .cpp 中编写的代码。
错误要么是这个
C:\Qt\Qt5.9.1\5.9.1\mingw53_32\include\QtCore\qvector.h:713: error: 使用已删除的功能'QGraphicsPixmapItem& QGraphicsPixmapItem::operator=(const QGraphicsPixmapItem&(' with the 唯一改变的是错误的位置(不同的标题 文件(
或者这个
C:\Qt\Qt5.9.1\5.9.1\mingw53_32\include\QtWidgets\qgraphicsitem.h:861: error: 'QGraphicsPixmapItem::QGraphicsPixmapItem(const QGraphicsPixmapItem&(' is private Q_DISABLE_COPY(QGraphicsPixmapItem( 在 qgraphicsitem.h 头文件中
生成的代码由于头文件中弹出的这些错误而无法编译
int count;
QVector<QBitmap> BitmapArrayTiles;
QVector<QGraphicsPixmapItem> PixmapItemsArray;
QGraphicsPixmapItem currentItem;
QBitmap currentBitmap;
QGraphicsScene *scene = new QGraphicsScene();
for(count = 0; count < 4; count++)
{
currentBitmap = QBitmap(150,150);
QPainter Painter(¤tBitmap);
QPen Pen(Qt::black); // just to be explicit
Painter.setPen(Pen);
drawStuff(Painter);
BitmapArrayTiles.insert(0, currentBitmap);
currentItem.setPixmap(BitmapArrayTiles[count]);
PixmapItemsArray.insert(count, currentItem);
scene->addItem(¤tItem);
currentItem.mapToScene((count*150)+150, (count*150)+150);
}
ui->TileView->setScene(scene);
^
我没有手动更改头文件,所以我不完全确定为什么会出现这些错误。
使用指针和眼泪
int count;
QGraphicsScene *scene = new QGraphicsScene(0, 0, 150*4, 150*4);
QVector<QBitmap*> BitmapArrayTiles;
QVector<QGraphicsPixmapItem*> BitmapItemsArray;
QGraphicsPixmapItem* CurrentItem;
QBitmap *CurrentBitmap;
const QBitmap* CurrentBitmapConstPointer = CurrentBitmap;
for(count = 0; count < 4; count++)
{
CurrentBitmap = new QBitmap(150,150);
QPainter Painter(CurrentBitmap);
QPen Pen(Qt::black); // just to be explicit
Painter.setPen(Pen);
drawStuff(Painter);
BitmapArrayTiles.insert(count, CurrentBitmap);
CurrentItem = new QGraphicsPixmapItem(*BitmapArrayTiles[count]);
BitmapItemsArray.insert(count, CurrentItem);
//PixmapItemsArray.insert(count, currentItem);
scene->addItem(BitmapItemsArray[count]);
BitmapItemsArray[count]->setPos((count*150)+150, (count*150)+150);
}
ui->TileView->setScene(scene);
- 与C++哈希表的基础知识混淆
- 基础知识指针 c++
- 使用 QVector 创建图形磁贴(QCache 之前的基础知识)
- 异常基础知识:为什么 while 循环会变成无限循环?
- Cortex-M0 ASF基础知识
- C++基础知识(使用其他方法(Unicode?)的相同代码)
- 2 个未解析的外部符号(C++函数基础知识)
- 了解线程构造函数的基础知识
- 了解写入副本的基础知识
- C++OOP基础知识-是否正确返回对象引用
- 计算DX11中的着色器基础知识
- MDI窗口和QSignalMapper基础知识
- P2P最重要的基础知识
- C 多循环 for () 基础知识
- C++指针和数组基础知识
- 堆叠基础知识
- c++编译的基础知识
- 如何开始学习用C++为XBOX 360 KINECT编写用于开发windows应用程序的程序的基础知识
- 链接列表基础知识中的混乱
- 运行 MEEP C++ 基础知识