# How to use pqLoadDataReaction and pqDataRepresentation correctly?

**URL:** https://discourse.paraview.org/t/how-to-use-pqloaddatareaction-and-pqdatarepresentation-correctly/11844
**Category:** Development
**Created:** [April 11, 2023, 7:48am UTC](https://discourse.paraview.org/t/how-to-use-pqloaddatareaction-and-pqdatarepresentation-correctly/11844 "2023-04-11T07:48:43Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![DG\_Kang](https://discourse.paraview.org/user_avatar/discourse.paraview.org/dg_kang/32/11352_2.png) [@DG\_Kang](https://discourse.paraview.org/u/DG_Kang)
#### Post date: [April 11, 2023, 7:48am UTC](https://discourse.paraview.org/t/how-to-use-pqloaddatareaction-and-pqdatarepresentation-correctly/11844/1 "2023-04-11T07:48:43Z")

</div>

Hi,  
I’m implementing my first custom application using QT, a few objects will be loaded into Paraview using the code and I have to change some properties, like color, size, position, etc.

I loaded the object with this code, it worked and the properties changed, but might crash.

I do not understand how the representation object and the view object work. Should I maintain a view object to load all the things in it? And is there some wrong with my code(except the empty check)?

```c++
pqAutoApplyReaction::setAutoApply(true);

QVector<pqPipelineSource *> QSourcePointer = pqLoadDataReaction::loadFilesForSupportedTypes(filelist);
pqDataRepresentation* representation = this->QSourcePointer->getRepresentation(this->QSourcePointer->getViews().at(0));
vtkSMPropertyHelper(representation->getProxy(), "Opacity").Set(0.25);

pqShowHideAllReaction::act(pqShowHideAllReaction::ActionType::Show);

```

The second thing is that sometimes I get an empty view object after loading one data object, so I can’t change any property of it in the same way.

```plaintext
QString filePath = this->cylinderPath;
if(FileTools::fileExist(filePath)){
   QStringList filePathList;
   QList<QStringList> fileList;
   filePathList << filePath;
   //If add the filePath twice, the size of the view object will be 1.
   //filePathList << filePath;
   fileList << filePathList;
   this->QSourcePointer = pqLoadDataReaction::loadFilesForSupportedTypes(fileList);
   
   // empty view object
   QList<pqView *> views = QSourcePointer.at(0)->getViews();
   pqDataRepresentation* representation = QSourcePointer.at(0)->getRepresentation(views.at(0));
}

```

---

<div class="post-metadata">

### Author: ![mwestphal](https://discourse.paraview.org/user_avatar/discourse.paraview.org/mwestphal/32/17_2.png) [@mwestphal](https://discourse.paraview.org/u/mwestphal)
#### Post date: [April 11, 2023, 8:43am UTC](https://discourse.paraview.org/t/how-to-use-pqloaddatareaction-and-pqdatarepresentation-correctly/11844/2 "2023-04-11T08:43:23Z")

</div>

> [@DG\_Kang](#):
>
> I do not understand how the representation object and the view object work. Should I maintain a view object to load all the things in it? And is there some wrong with my code(except the empty check)?

I dont see anything wrong with your code.

You may want to rely on the ActiveView/ActiveSource logic.

---

<div class="post-metadata">

### Author: ![DG\_Kang](https://discourse.paraview.org/user_avatar/discourse.paraview.org/dg_kang/32/11352_2.png) [@DG\_Kang](https://discourse.paraview.org/u/DG_Kang)
#### Post date: [April 11, 2023, 11:24am UTC](https://discourse.paraview.org/t/how-to-use-pqloaddatareaction-and-pqdatarepresentation-correctly/11844/3 "2023-04-11T11:24:28Z")

</div>

Thanks for your answer. Where can I get the ActiveView/ActiveSource logic information? only by reading source code? Is that possible to specify a view to load data in pqLoadDataReaction?

---

<div class="post-metadata">

### Author: ![mwestphal](https://discourse.paraview.org/user_avatar/discourse.paraview.org/mwestphal/32/17_2.png) [@mwestphal](https://discourse.paraview.org/u/mwestphal)
#### Post date: [April 11, 2023, 12:00pm UTC](https://discourse.paraview.org/t/how-to-use-pqloaddatareaction-and-pqdatarepresentation-correctly/11844/4 "2023-04-11T12:00:33Z")

</div>

[https://kitware.github.io/paraview-docs/latest/cxx/classpqActiveObjects.html](https://kitware.github.io/paraview-docs/latest/cxx/classpqActiveObjects.html)

> Is that possible to specify a view to load data in pqLoadDataReaction?

No, use `vtkSMParaViewPipelineControllerWithRendering::Show` to show a source in a view.

---

<div class="post-metadata">

### Author: ![DG\_Kang](https://discourse.paraview.org/user_avatar/discourse.paraview.org/dg_kang/32/11352_2.png) [@DG\_Kang](https://discourse.paraview.org/u/DG_Kang)
#### Post date: [April 28, 2023, 11:07am UTC](https://discourse.paraview.org/t/how-to-use-pqloaddatareaction-and-pqdatarepresentation-correctly/11844/5 "2023-04-28T11:07:49Z")

</div>

I have identified the cause of the crash. I tried to access index 0 of _getViews()_, but unfortunately, the views are currently empty. I have written a code to pause momentarily and ensure that the view is fully prepared before proceeding.

```auto
bool SphDockWidget::wait_view(){
    bool success = false;
    int count = 10;

    while (!success && count >= 0) {
        if(!this->QSourcePointer.empty()) {
            if (!this->QSourcePointer.at(0)->getViews().empty()) {
                success = true;
            }
        }

        if (!success) {
            QEventLoop loop;
            QTimer::singleShot(10, &loop, &QEventLoop::quit);

            loop.exec();
            count--;
        }
    }
    return success;
}

```
