# lv_qrcode.h (/api/public/widgets/lv_qrcode_h)



<RelatedHeaders name="lv_qrcode_private.h" isPrivate="false" />

<ApiSummary functions="11" enums="1" variables="1" />

Functions [#functions]

<ApiTabs items="[&#x22;Setters (6)&#x22;,&#x22;Getters (1)&#x22;,&#x22;Other (4)&#x22;]">
  <ApiTab value="Setters (6)">
    <ApiMember kind="function" name="lv_qrcode_set_size" file="public/widgets/lv_qrcode.h" line="63" url="https://github.com/lvgl/lvgl/tree/e1a0ad863f29742359bc680d6a7d973448ec2285/include/lvgl/widgets/lv_qrcode.h#L63">
      lv_qrcode_set_size [#lv_qrcode_set_size]

      Set QR code size.

      ```c title=" " lineNumbers=1
      void lv_qrcode_set_size(lv_obj_t *obj, int32_t size)
      ```

      <span className="sr-only">
        Parameters
      </span>

      | Name   | Type                                             | Description                     |
      | ------ | ------------------------------------------------ | ------------------------------- |
      | `obj`  | <ApiLink name="lv_obj_t" display="lv_obj_t *" /> | pointer to a QR code object     |
      | `size` | `int32_t`                                        | width and height of the QR code |
    </ApiMember>

    <ApiMember kind="function" name="lv_qrcode_set_dark_color" file="public/widgets/lv_qrcode.h" line="70" url="https://github.com/lvgl/lvgl/tree/e1a0ad863f29742359bc680d6a7d973448ec2285/include/lvgl/widgets/lv_qrcode.h#L70">
      lv_qrcode_set_dark_color [#lv_qrcode_set_dark_color]

      Set QR code dark color.

      ```c title=" " lineNumbers=1
      void lv_qrcode_set_dark_color(lv_obj_t *obj, lv_color_t color)
      ```

      <span className="sr-only">
        Parameters
      </span>

      | Name    | Type                                             | Description                 |
      | ------- | ------------------------------------------------ | --------------------------- |
      | `obj`   | <ApiLink name="lv_obj_t" display="lv_obj_t *" /> | pointer to a QR code object |
      | `color` | <ApiLink name="lv_color_t" />                    | dark color of the QR code   |
    </ApiMember>

    <ApiMember kind="function" name="lv_qrcode_set_light_color" file="public/widgets/lv_qrcode.h" line="77" url="https://github.com/lvgl/lvgl/tree/e1a0ad863f29742359bc680d6a7d973448ec2285/include/lvgl/widgets/lv_qrcode.h#L77">
      lv_qrcode_set_light_color [#lv_qrcode_set_light_color]

      Set QR code light color.

      ```c title=" " lineNumbers=1
      void lv_qrcode_set_light_color(lv_obj_t *obj, lv_color_t color)
      ```

      <span className="sr-only">
        Parameters
      </span>

      | Name    | Type                                             | Description                 |
      | ------- | ------------------------------------------------ | --------------------------- |
      | `obj`   | <ApiLink name="lv_obj_t" display="lv_obj_t *" /> | pointer to a QR code object |
      | `color` | <ApiLink name="lv_color_t" />                    | light color of the QR code  |
    </ApiMember>

    <ApiMember kind="function" name="lv_qrcode_set_data" file="public/widgets/lv_qrcode.h" line="98" url="https://github.com/lvgl/lvgl/tree/e1a0ad863f29742359bc680d6a7d973448ec2285/include/lvgl/widgets/lv_qrcode.h#L98">
      lv_qrcode_set_data [#lv_qrcode_set_data]

      Helper function to set the data of a QR code object from a string. The NUL terminator is not part of the encoded payload.

      ```c title=" " lineNumbers=1
      void lv_qrcode_set_data(lv_obj_t *obj, const char *data)
      ```

      <span className="sr-only">
        Parameters
      </span>

      | Name   | Type                                             | Description                                |
      | ------ | ------------------------------------------------ | ------------------------------------------ |
      | `obj`  | <ApiLink name="lv_obj_t" display="lv_obj_t *" /> | pointer to a QR code object                |
      | `data` | `const char *`                                   | data to display as a NUL terminated string |
    </ApiMember>

    <ApiMember kind="function" name="lv_qrcode_set_quiet_zone" file="public/widgets/lv_qrcode.h" line="118" url="https://github.com/lvgl/lvgl/tree/e1a0ad863f29742359bc680d6a7d973448ec2285/include/lvgl/widgets/lv_qrcode.h#L118">
      lv_qrcode_set_quiet_zone [#lv_qrcode_set_quiet_zone]

      Enable or disable quiet zone. Quiet zone is the area around the QR code where no data is encoded.

      ```c title=" " lineNumbers=1
      void lv_qrcode_set_quiet_zone(lv_obj_t *obj, bool enable)
      ```

      <span className="sr-only">
        Parameters
      </span>

      | Name     | Type                                             | Description                                        |
      | -------- | ------------------------------------------------ | -------------------------------------------------- |
      | `obj`    | <ApiLink name="lv_obj_t" display="lv_obj_t *" /> | pointer to a QR code object                        |
      | `enable` | `bool`                                           | true: enable quiet zone; false: disable quiet zone |
    </ApiMember>

    <ApiMember kind="function" name="lv_qrcode_set_update_mode" file="public/widgets/lv_qrcode.h" line="139" url="https://github.com/lvgl/lvgl/tree/e1a0ad863f29742359bc680d6a7d973448ec2285/include/lvgl/widgets/lv_qrcode.h#L139">
      lv_qrcode_set_update_mode [#lv_qrcode_set_update_mode]

      Set when a property change is turned into a new QR code bitmap. With LV\_QRCODE\_UPDATE\_MODE\_IMMEDIATE (the default) changing the size or the quiet zone re-encodes the stored data right away. With LV\_QRCODE\_UPDATE\_MODE\_DEFERRED such a change only marks the bitmap as out of date and several changes are collapsed into a single re-encode on the next redraw.

      ```c title=" " lineNumbers=1
      void lv_qrcode_set_update_mode(lv_obj_t *obj, lv_qrcode_update_mode_t mode)
      ```

      <span className="sr-only">
        Parameters
      </span>

      | Name   | Type                                             | Description                 |
      | ------ | ------------------------------------------------ | --------------------------- |
      | `obj`  | <ApiLink name="lv_obj_t" display="lv_obj_t *" /> | pointer to a QR code object |
      | `mode` | <ApiLink name="lv_qrcode_update_mode_t" />       | the mode to use             |

      <Callout type="info">
        In deferred mode you are expected to call <ApiLink name="lv_qrcode_render" display="lv_qrcode_render()" /> yourself once the properties are set. It encodes right away and returns the result, leaving the next redraw nothing to do. If it is forgotten, the encode is done by the redraw instead: the bitmap is still correct, but the work is charged to that refresh and its result cannot be reported to anyone, so a warning is logged. Prefer the explicit call.
      </Callout>

      <Callout type="info">
        Switching back to LV\_QRCODE\_UPDATE\_MODE\_IMMEDIATE while the bitmap is out of date also re-encodes it, but this function returns void, so an encode failure can only be logged, not reported. A warning is emitted in that case. Call <ApiLink name="lv_qrcode_render" display="lv_qrcode_render()" /> first and switch the mode afterwards to get the result.
      </Callout>
    </ApiMember>
  </ApiTab>

  <ApiTab value="Getters (1)">
    <ApiMember kind="function" name="lv_qrcode_get_update_mode" file="public/widgets/lv_qrcode.h" line="146" url="https://github.com/lvgl/lvgl/tree/e1a0ad863f29742359bc680d6a7d973448ec2285/include/lvgl/widgets/lv_qrcode.h#L146">
      lv_qrcode_get_update_mode [#lv_qrcode_get_update_mode]

      Get when a property change is turned into a new QR code bitmap.

      ```c title=" " lineNumbers=1
      lv_qrcode_update_mode_t lv_qrcode_get_update_mode(lv_obj_t *obj)
      ```

      <span className="sr-only">
        Parameters
      </span>

      | Name  | Type                                             | Description                 |
      | ----- | ------------------------------------------------ | --------------------------- |
      | `obj` | <ApiLink name="lv_obj_t" display="lv_obj_t *" /> | pointer to a QR code object |

      **Returns:** <ApiLink name="lv_qrcode_update_mode_t" /> — the update mode currently in use
    </ApiMember>
  </ApiTab>

  <ApiTab value="Other (4)">
    <ApiMember kind="function" name="lv_qrcode_create" file="public/widgets/lv_qrcode.h" line="56" url="https://github.com/lvgl/lvgl/tree/e1a0ad863f29742359bc680d6a7d973448ec2285/include/lvgl/widgets/lv_qrcode.h#L56">
      lv_qrcode_create [#lv_qrcode_create]

      Create an empty QR code (an `lv_canvas`) object.

      ```c title=" " lineNumbers=1
      lv_obj_t * lv_qrcode_create(lv_obj_t *parent)
      ```

      <span className="sr-only">
        Parameters
      </span>

      | Name     | Type                                             | Description                                                                                                        |
      | -------- | ------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------ |
      | `parent` | <ApiLink name="lv_obj_t" display="lv_obj_t *" /> | pointer to a parent widget **May** be `NULL`.. When NULL, the widget is created as a screen on the active display. |

      **Returns:** <ApiLink name="lv_obj_t" display="lv_obj_t *" /> — pointer to the created QR code object
    </ApiMember>

    <ApiMember kind="function" name="lv_qrcode_update" file="public/widgets/lv_qrcode.h" line="90" url="https://github.com/lvgl/lvgl/tree/e1a0ad863f29742359bc680d6a7d973448ec2285/include/lvgl/widgets/lv_qrcode.h#L90">
      lv_qrcode_update [#lv_qrcode_update]

      Set the data of a QR code object and generate the bitmap. A copy of the data is stored, so a later <ApiLink name="lv_qrcode_set_size" display="lv_qrcode_set_size()" /> or <ApiLink name="lv_qrcode_set_quiet_zone" display="lv_qrcode_set_quiet_zone()" /> can re-encode it. The properties may therefore be set before or after the data, in any order. Use <ApiLink name="lv_qrcode_render" display="lv_qrcode_render()" /> to re-encode the stored payload without passing it again.

      ```c title=" " lineNumbers=1
      lv_result_t lv_qrcode_update(lv_obj_t *obj, const void *data, uint32_t data_len)
      ```

      <span className="sr-only">
        Parameters
      </span>

      | Name       | Type                                             | Description                 |
      | ---------- | ------------------------------------------------ | --------------------------- |
      | `obj`      | <ApiLink name="lv_obj_t" display="lv_obj_t *" /> | pointer to a QR code object |
      | `data`     | `const void *`                                   | data to display             |
      | `data_len` | `uint32_t`                                       | length of `data` in bytes   |

      **Returns:** <ApiLink name="lv_result_t" /> — LV\_RESULT\_OK: if no error; LV\_RESULT\_INVALID: on error
    </ApiMember>

    <ApiMember kind="function" name="lv_qrcode_render" file="public/widgets/lv_qrcode.h" line="110" url="https://github.com/lvgl/lvgl/tree/e1a0ad863f29742359bc680d6a7d973448ec2285/include/lvgl/widgets/lv_qrcode.h#L110">
      lv_qrcode_render [#lv_qrcode_render]

      (Re)generate the QR code bitmap from the payload that is already stored. Unlike <ApiLink name="lv_qrcode_update" display="lv_qrcode_update()" /> this needs no payload, so it is the way to apply property changes made in LV\_QRCODE\_UPDATE\_MODE\_DEFERRED: set the size and quiet zone, then call this once to encode them and get the result. The bitmap is regenerated whether or not anything changed.

      ```c title=" " lineNumbers=1
      lv_result_t lv_qrcode_render(lv_obj_t *obj)
      ```

      <span className="sr-only">
        Parameters
      </span>

      | Name  | Type                                             | Description                 |
      | ----- | ------------------------------------------------ | --------------------------- |
      | `obj` | <ApiLink name="lv_obj_t" display="lv_obj_t *" /> | pointer to a QR code object |

      **Returns:** <ApiLink name="lv_result_t" /> — LV\_RESULT\_OK: if no error; LV\_RESULT\_INVALID: on error (e.g. no data set, or the payload does not fit the current size)
    </ApiMember>

    <ApiMember kind="function" name="lv_qrcode_is_render_valid" file="public/widgets/lv_qrcode.h" line="164" url="https://github.com/lvgl/lvgl/tree/e1a0ad863f29742359bc680d6a7d973448ec2285/include/lvgl/widgets/lv_qrcode.h#L164">
      lv_qrcode_is_render_valid [#lv_qrcode_is_render_valid]

      Check whether the QR code bitmap is free of a known encode failure. Most encodes report their result directly: <ApiLink name="lv_qrcode_update" display="lv_qrcode_update()" /> returns it. The ones that cannot are the re-encodes triggered by a property change - they happen in a void setter or, in LV\_QRCODE\_UPDATE\_MODE\_DEFERRED, in the draw pass. Use this to detect those, e.g. after shrinking the object below the size its payload needs.

      ```c title=" " lineNumbers=1
      bool lv_qrcode_is_render_valid(lv_obj_t *obj)
      ```

      <span className="sr-only">
        Parameters
      </span>

      | Name  | Type                                             | Description                 |
      | ----- | ------------------------------------------------ | --------------------------- |
      | `obj` | <ApiLink name="lv_obj_t" display="lv_obj_t *" /> | pointer to a QR code object |

      **Returns:** `bool` — true: no encode attempt is known to have failed. A property change re-arms the Widget, so this is also true while a deferred re-encode is still pending; false: the last encode attempt failed, or no data has been set yet

      <Callout type="info">
        A failed encode leaves the bitmap marked as out of date, so it is never reported as current, and it is not retried on every redraw - only a property change makes the Widget try again. Encode failures are not logged when the caller can see the result; the one exception is the re-encode done by the redraw, which has no caller, so that one is logged.
      </Callout>
    </ApiMember>
  </ApiTab>
</ApiTabs>

Enums [#enums]

<ApiMember kind="enum" name="lv_qrcode_update_mode_t" file="public/widgets/lv_qrcode.h" line="39" url="https://github.com/lvgl/lvgl/tree/e1a0ad863f29742359bc680d6a7d973448ec2285/include/lvgl/widgets/lv_qrcode.h#L39">
  lv_qrcode_update_mode_t [#lv_qrcode_update_mode_t]

  Controls when a property change is turned into a new QR code bitmap. Only the properties that require re-encoding (size, quiet zone) are affected; <ApiLink name="lv_qrcode_update" display="lv_qrcode_update()" /> always encodes right away and the colors are always a palette-only write.

  | Name                              | Value | Description                                                             |
  | --------------------------------- | ----- | ----------------------------------------------------------------------- |
  | `LV_QRCODE_UPDATE_MODE_IMMEDIATE` | `0`   | Re-encode as soon as a property changes (default)                       |
  | `LV_QRCODE_UPDATE_MODE_DEFERRED`  |       | Only mark the bitmap out of date and re-encode once, on the next redraw |
</ApiMember>

<TypeUsedBy name="lv_qrcode_update_mode_t" count="1">
  * `lv_qrcode_set_update_mode` — param `mode`
</TypeUsedBy>

Variables [#variables]

<ApiMember kind="variable" name="lv_qrcode_class" file="public/widgets/lv_qrcode.h" line="44" url="https://github.com/lvgl/lvgl/tree/e1a0ad863f29742359bc680d6a7d973448ec2285/include/lvgl/widgets/lv_qrcode.h#L44">
  lv_qrcode_class [#lv_qrcode_class]

  ```c title=" " lineNumbers=1
  const lv_obj_class_t lv_qrcode_class
  ```
</ApiMember>

Dependencies [#dependencies]

<FileIncludes includes="[&#x22;lv_conf_internal.h&#x22;, &#x22;lv_color.h&#x22;, &#x22;lv_types.h&#x22;, &#x22;lv_canvas.h&#x22;, &#x22;stdbool.h&#x22;, &#x22;stdint.h&#x22;]" includedBy="[&#x22;lvgl.h&#x22;]" transitiveIncludes="[&#x22;lv_anim.h&#x22;, &#x22;lv_area.h&#x22;, &#x22;lv_assert.h&#x22;, &#x22;lv_bidi.h&#x22;, &#x22;lv_color_op.h&#x22;, &#x22;lv_display.h&#x22;, &#x22;lv_draw.h&#x22;, &#x22;lv_draw_arc.h&#x22;, &#x22;lv_draw_blur.h&#x22;, &#x22;lv_draw_buf.h&#x22;, &#x22;lv_draw_image.h&#x22;, &#x22;lv_draw_label.h&#x22;, &#x22;lv_draw_line.h&#x22;, &#x22;lv_draw_rect.h&#x22;, &#x22;lv_draw_triangle.h&#x22;, &#x22;lv_event.h&#x22;, &#x22;lv_ext_data.h&#x22;, &#x22;lv_flex.h&#x22;, &#x22;lv_font.h&#x22;, &#x22;lv_fs.h&#x22;, &#x22;lv_grad.h&#x22;, &#x22;lv_grid.h&#x22;, &#x22;lv_group.h&#x22;, &#x22;lv_image.h&#x22;, &#x22;lv_image_decoder.h&#x22;, &#x22;lv_image_dsc.h&#x22;, &#x22;lv_indev.h&#x22;, &#x22;lv_layout.h&#x22;, &#x22;lv_ll.h&#x22;, &#x22;lv_log.h&#x22;, &#x22;lv_math.h&#x22;, &#x22;lv_matrix.h&#x22;, &#x22;lv_mem.h&#x22;, &#x22;lv_obj.h&#x22;, &#x22;lv_obj_class.h&#x22;, &#x22;lv_obj_draw.h&#x22;, &#x22;lv_obj_event.h&#x22;, &#x22;lv_obj_pos.h&#x22;, &#x22;lv_obj_property.h&#x22;, &#x22;lv_obj_scroll.h&#x22;, &#x22;lv_obj_style.h&#x22;, &#x22;lv_obj_style_gen.h&#x22;, &#x22;lv_obj_tree.h&#x22;, &#x22;lv_observer.h&#x22;, &#x22;lv_palette.h&#x22;, &#x22;lv_profiler.h&#x22;, &#x22;lv_profiler_builtin.h&#x22;, &#x22;lv_sprintf.h&#x22;, &#x22;lv_string.h&#x22;, &#x22;lv_style.h&#x22;, &#x22;lv_style_gen.h&#x22;, &#x22;lv_symbol_def.h&#x22;, &#x22;lv_text.h&#x22;, &#x22;lv_timer.h&#x22;]" />
