Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. 3rd Party Software
  4. [SOLVED] Lighter setup for serial port parameters (qSerialDevice)
QtWS25 Last Chance

[SOLVED] Lighter setup for serial port parameters (qSerialDevice)

Scheduled Pinned Locked Moved 3rd Party Software
5 Posts 3 Posters 3.0k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    david.luggen
    wrote on 1 Mar 2012, 14:26 last edited by
    #1

    Hey there

    If I want to save the last serial port parameters to initialize this port at the next program start, I used always big switch statements like this one:

    @switch(i)
    {
    case 0:
    port->setParity(SerialPort::EvenParity);
    break;
    case 1:
    port->setParity(SerialPort::OddParity);
    break;
    case 2:
    port->setParity(SerialPort::NoParity);
    break;
    case 3:
    port->setParity(SerialPort::MarkParity);
    break;
    case 4:
    port->setParity(SerialPort::SpaceParity);
    break;
    }@

    Is it possible to save these different serial port parameters into a QList or something similar, so I would be able to reduce all of this into one line? Something like this:

    @QList<SerialPort> databits << SerialPort::Data5 << SerialPort::Data6 << SerialPort::Data7 << SerialPort::Data8;@

    And then:

    @port->setDataBits(databits[i]);@

    Unfortunately it does not work with a QList, or I haven't found the right method to do this.

    1 Reply Last reply
    0
    • T Offline
      T Offline
      tobias.hunger
      wrote on 1 Mar 2012, 14:30 last edited by
      #2

      Assuming that SerialPort::EvenParity, etc. are actually enums: Why don't you just cast those to an int, save that into "serialPort/parityIndex" (which should be surrounded by QLatin1String(...) by the way) and then call port->setParity(SerialPort::WhatEverEnum(value)?

      1 Reply Last reply
      0
      • T Offline
        T Offline
        tobias.hunger
        wrote on 1 Mar 2012, 14:32 last edited by
        #3

        PS: Since the enum values are not of type SerialPort the QList<SerialPort> databits thing can not work. You need to use the type of the enum, not the class containing it there.

        1 Reply Last reply
        0
        • D Offline
          D Offline
          david.luggen
          wrote on 5 Mar 2012, 13:42 last edited by
          #4

          Thx for the advice. As you said my fault was the type of the QList. I just needed to set the type to:

          @QListSerialPort::DataBits databits@

          with the DataBits enum for example.

          It is also possible to use the integer value. But in my application I use QComboBox to adjust the serialPort. Finally I save the index value of the QComboBox when the settings are applied. If I want to use these integers to set the serial port parameteres it gets a bit confusing because the enums have different values. For example:

          @ enum Parity {
          NoParity = 0,
          EvenParity = 2,
          OddParity = 3,
          SpaceParity = 4,
          MarkParity = 5,
          UnknownParity = -1
          };@

          Therefore it's anyway useful to fill a QList in the order like you want it, isn't it?

          1 Reply Last reply
          0
          • K Offline
            K Offline
            kuzulis
            Qt Champions 2020
            wrote on 6 Mar 2012, 07:02 last edited by
            #5

            2 luggi,

            see examples in /tests/guiapp/optionsdialog.cpp

            1 Reply Last reply
            0

            5/5

            6 Mar 2012, 07:02

            • Login

            • Login or register to search.
            5 out of 5
            • First post
              5/5
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved