2017-08-23 6 views
0

私は、グラフィックス表示をタイルグラフィックスレンダリングを使用するようにアップグレードしようとしています。私はこのプロセスにはほとんど慣れていませんが、簡単な例を作成しようとする私の試みは以下の通りです。私がQVectorまたはQCacheのどちらかを使用する必要がある理由(私はQVectorを簡単にするために現在使用しています)は、RAMとそのタイルをオンザフライで作成する必要がありません。私はあなたが私が以下でやろうとしていることをすることができるかどうかは完全にはわかりませんが、本質的にはビットマップの配列を作成し、アイテムを作成してシーンに追加しようとします。このプログラムをコンパイルすると、12個のエラーがありますが、mainWindow.cppで作成したコードを直接参照するものはありません。QVectorを使用してグラフィックスタイルを作成する(QCache前の基本)

エラーがされているか、この

C:\Qt\Qt5.9.1\5.9.1\mingw53_32\include\QtCore\qvector.h:713: error: use of deleted function 'QGraphicsPixmapItem& QGraphicsPixmapItem::operator=(const QGraphicsPixmapItem&)' with the only thing changing being the location of the error (different header files)

またはこの

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) which is in the qgraphicsitem.h header file

ヘッダファイルにポップアップによるこれらのエラーをコンパイルできない生成コード

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(&currentBitmap); 
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(&currentItem); 
currentItem.mapToScene((count*150)+150, (count*150)+150); 
} 
ui->TileView->setScene(scene); 
      ^

私は手動でヘッダファイルを変更していないので、なぜこれらのエラーが出るのか全然わからない。

+0

はQObjectはコピーできません。 Qt4のやり方は、オブジェクトの代わりにポインタを使うことでした。 – drescherjm

+0

https://stackoverflow.com/questions/19854371/repeating-q-disable-copy-in-qobject-derived-classes – drescherjm

+0

https://stackoverflow.com/questions/2652504/how-do-i-copy-object -in-qt – drescherjm

答えて

0

使用ポインタと涙

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); 
+0

'QBitmap'をポインタとしてポインタに格納する必要はありません。これらは自動変数にすることができます。 – thuga

関連する問題