构造函数中的QGraphicsScene *场景出错

时间:2016-05-30 21:20:44

标签: qt qgraphicsscene

我仍然遇到QGraphicsScene的问题

我创建了一个名为Gioco的小部件,我在构造函数中声明了*场景

Gioco::Gioco()
{
    QGraphicsScene *scene = new QGraphicsScene();
    scene -> setSceneRect(0,0,1980,1200);
    setScene(scene);
}

现在我想在void中使用相同的*场景,但是我得到错误未定的引用* scene

void Gioco::partita()
{extern QGraphicsScene *scene;

    //create a new Pixmap Item
    QGraphicsPixmapItem *img_mazzo = new QGraphicsPixmapItem();
    img_mazzo -> setPixmap(QPixmap(":/Media/Immagini/dorso.jpg"));

    //add to scene
    scene -> addItem(img_mazzo);
}

我该如何解决这个错误? 感谢

1 个答案:

答案 0 :(得分:2)

您收到错误,因为 public function actionDeselect() { $picking_list = Yii::$app->request->get('pick'); $item_id = Yii::$app->request->get('item'); $deselectModel = PickedItems::find()->where(['item_id' => $item_id, 'picking_list' => $picking_list])->one(); $itemAdded = Inventory::find()->where(['inv_id' => $item_id])->one(); $itemAdded->inv_status = 1; $itemAdded->current_ot = '0'; $deselectModel->delete(); $itemAdded->save(); } public function actionAdd() { $picking_list = Yii::$app->request->get('pick'); $item_id = Yii::$app->request->get('item'); $itemAdded = Inventory::find()->where(['inv_id' => $item_id])->one(); $currentPicking = PickingList::find()->where(['pick_id' => $picking_list])->one(); $currentOt = Ot::find()->where(['ot_id' => $currentPicking->ot_id])->one(); if($itemAdded->composition === 2){ $parentGroup = $itemAdded->parent_code; $otherItems = Inventory::find()->where(['parent_code' => $parentGroup])->all(); foreach($otherItems as $item){ $addModel = new PickedItems(); $addModel->picking_list = $picking_list; $addModel->item_id = $item->inv_id; $addModel->save(); $item->inv_status = 2; $item->current_ot = $currentOt->ot_id; $item->save(); } } else{ $addModel = new PickedItems(); $addModel->picking_list = $picking_list; $addModel->item_id = $item_id; $addModel->save(); $itemAdded->inv_status = 2; $itemAdded->current_ot = $currentOt->ot_id; $itemAdded->save(); } } 声明了一个未在任何地方定义的全局变量。

您可能希望场景成为成员变量,并且不需要使用显式动态分配:

extern QGraphicsScene * scene