# Safe way to get access to one of painter devices

**URL:** <https://discuss.avogadro.cc/t/safe-way-to-get-access-to-one-of-painter-devices/1677>\
**Category:** Development\
**Created:** [November 24, 2009, 3:41pm UTC](https://discuss.avogadro.cc/t/safe-way-to-get-access-to-one-of-painter-devices/1677 "2009-11-24T15:41:55Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Konstantin\_Tokarev](https://discuss.avogadro.cc/letter_avatar_proxy/v4/letter/k/ecd19e/32.png) [@Konstantin\_Tokarev](https://discuss.avogadro.cc/u/Konstantin_Tokarev)\
**Post date:** [November 24, 2009, 3:41pm UTC](https://discuss.avogadro.cc/t/safe-way-to-get-access-to-one-of-painter-devices/1677/1 "2009-11-24T15:41:55Z")

</div>

## In my version of labelsettingswidget I’ve created “preview” box, which displays how label of 1st atom of molecule will be displayed using current style. But I need access to molecule from function other than renderOpaque, which accepts PainterDevice as parameter. I’ve strored pointer to first used PainterDevice, but it causes segfault if one more file is opened

Regards,  
Konstantin

---

<div class="post-metadata">

**Author:** ![ghutchis](https://discuss.avogadro.cc/user_avatar/discuss.avogadro.cc/ghutchis/32/456_2.png) [@ghutchis](https://discuss.avogadro.cc/u/ghutchis)\
**Post date:** [November 24, 2009, 4:16pm UTC](https://discuss.avogadro.cc/t/safe-way-to-get-access-to-one-of-painter-devices/1677/2 "2009-11-24T16:16:33Z")

</div>

On Nov 24, 2009, at 10:41 AM, Konstantin Tokarev wrote:

> In my version of labelsettingswidget I’ve created “preview” box, which displays how label of 1st atom of molecule will be displayed using current style.

Why do we need the 1st atom? Can’t we use an arbitrary atom like a carbon?

Cheers,  
-Geoff

---

<div class="post-metadata">

**Author:** ![Konstantin\_Tokarev](https://discuss.avogadro.cc/letter_avatar_proxy/v4/letter/k/ecd19e/32.png) [@Konstantin\_Tokarev](https://discuss.avogadro.cc/u/Konstantin_Tokarev)\
**Post date:** [November 24, 2009, 4:31pm UTC](https://discuss.avogadro.cc/t/safe-way-to-get-access-to-one-of-painter-devices/1677/3 "2009-11-24T16:31:20Z")

</div>

> Why do we need the 1st atom? Can’t we use an arbitrary atom like a carbon?

## I thought about it. I simply create a static global Atom in labelengine.cpp and set some arbitrary values for formalCharge, partialCharge, residue, etc But in atom.h is written “All atoms must be owned by a Molecule”

Regards,  
Konstantin

---

<div class="post-metadata">

**Author:** ![ghutchis](https://discuss.avogadro.cc/user_avatar/discuss.avogadro.cc/ghutchis/32/456_2.png) [@ghutchis](https://discuss.avogadro.cc/u/ghutchis)\
**Post date:** [November 24, 2009, 5:02pm UTC](https://discuss.avogadro.cc/t/safe-way-to-get-access-to-one-of-painter-devices/1677/4 "2009-11-24T17:02:36Z")

</div>

> I thought about it. I simply create a static global Atom in labelengine.cpp and set some arbitrary values for formalCharge, partialCharge, residue, etc  
> But in atom.h is written “All atoms must be owned by a Molecule”

I don’t think that’s a big deal for what you want. I think it’ll work.

Cheers,  
-Geoff

---

<div class="post-metadata">

**Author:** ![mhanwell](https://discuss.avogadro.cc/user_avatar/discuss.avogadro.cc/mhanwell/32/16_2.png) [@mhanwell](https://discuss.avogadro.cc/u/mhanwell)\
**Post date:** [November 26, 2009, 12:29am UTC](https://discuss.avogadro.cc/t/safe-way-to-get-access-to-one-of-painter-devices/1677/5 "2009-11-26T00:29:15Z")

</div>

Geoffrey Hutchison wrote:

> > I thought about it. I simply create a static global Atom in labelengine.cpp and set some arbitrary values for formalCharge, partialCharge, residue, etc  
> > But in atom.h is written “All atoms must be owned by a Molecule”
> 
> I don’t think that’s a big deal for what you want. I think it’ll work.

For what you want it will work fine unless you try getting the atom’s  
position. Then it would fail, probably with a segfault.

Marcus
