Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to properly keep settings for 20 identical signal channels
Forum Updated to NodeBB v4.3 + New Features

How to properly keep settings for 20 identical signal channels

Scheduled Pinned Locked Moved Solved General and Desktop
10 Posts 4 Posters 1.8k Views 2 Watching
  • 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.
  • A Offline
    A Offline
    Andrey Shmelew
    wrote on last edited by Andrey Shmelew
    #1

    I have a device with 20 identical signal channels.
    They have identical list of many parametrs, and i want to keep the parametrs properly.
    I Have a common class

    #Channel.h

    class ChannelOptions
    {
    public:
        static int count222;
    
    public :  int count;
    
    public:
    
        QString GetUnitsName();
    
        int GetSignalType1();
        int GetSignalType();
        int GetLowerLimit();
        int GetHigherLimit();
        int GetLowerMeasureLimit();
        int GetHigherMeasureLimit();
    
        void SetSignalType(int newsignaltype);
        void SetLowerLimit(int newsignaltype);
        void SetHigherLimit(int newhigherlimit);
        void SetLowerMeasureLimit(int newlowermeaslimit);
        void SetHigherMeasureLimit(int newhighermeaslimit);
        void SetUnitsName(QString newunit);
    
        // приватные переменные настроек канала 1
    
    private:
    
        int signaltype;
        int lowerlimit;
        int higherlimit;
        int lowermeasurelimit;
        int highermeasurelimit;
        int measureperiodsecond;
        QString unitsname;
    };
    

    Have methods:

    #Channel.cpp

    void ChannelOptions::SetUnitsName(QString newunitname)
    {
        unitsname = newunitname;
    }
    
    QString ChannelOptions::GetUnitsName()
    {
        return unitsname;
    }
    

    Have UI form called Options.

    #Options.cpp

    Options::Options(QWidget *parent) :
        QDialog(parent),
        ui(new Ui::Options)
    {
        ui->setupUi(this);
        setWindowFlags(Qt::CustomizeWindowHint);
        setWindowTitle(tr("OPTIONS"));
        connect(ui->UnChan1RadButOtkl, SIGNAL(pressed()), this, SLOT(checkboxchange()) );
    
    
        // параметры для каждого канала
    
        ChannelOptions options1;
        ChannelOptions options2;
    
        options1.SetUnitsName("Ampers");
        options2.SetUnitsName("Volts");
    
        qDebug() << options1.GetUnitsName();
        qDebug() << options2.GetUnitsName();
    }
    

    But also i want to Set units name for any channel by button click (or any other actions in UI)

    void Options::on_pushButton_clicked()
    {
        options1.SetUnitsName("Degrees");
        qDebug() << options1.GetUnitsName();
    }
    

    So i want to know... is it a properly way to keep the settings like this for each of 20 channel

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi
      If you move
      ChannelOptions options1;
      ChannelOptions options2;
      To the .h file so they are member variables then it seems fine.

      I most likely would use a list and not have 20 variables
      QList<ChannelOptions> ChannelOptionsList;
      ChannelOptions tempoptions1;
      tempoptions1.SetUnitsName("Ampers");

      ChannelOptionsList.append(tempoptions1);

      qDebug() << ChannelOptionsList.at(0).GetUnitsName();

      A 1 Reply Last reply
      0
      • mrjjM mrjj

        Hi
        If you move
        ChannelOptions options1;
        ChannelOptions options2;
        To the .h file so they are member variables then it seems fine.

        I most likely would use a list and not have 20 variables
        QList<ChannelOptions> ChannelOptionsList;
        ChannelOptions tempoptions1;
        tempoptions1.SetUnitsName("Ampers");

        ChannelOptionsList.append(tempoptions1);

        qDebug() << ChannelOptionsList.at(0).GetUnitsName();

        A Offline
        A Offline
        Andrey Shmelew
        wrote on last edited by
        #3

        @mrjj
        Thanks, but
        qDebug() << ChannelOptionsList.at(0).GetUnitsName();
        returns error C2662

        jsulmJ 1 Reply Last reply
        0
        • A Andrey Shmelew

          @mrjj
          Thanks, but
          qDebug() << ChannelOptionsList.at(0).GetUnitsName();
          returns error C2662

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @Andrey-Shmelew Did you add any ChannelOptions to the list?
          And you should post the whole error message not only its id.

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          A 1 Reply Last reply
          0
          • jsulmJ jsulm

            @Andrey-Shmelew Did you add any ChannelOptions to the list?
            And you should post the whole error message not only its id.

            A Offline
            A Offline
            Andrey Shmelew
            wrote on last edited by
            #5

            @jsulm
            sorry, i can not post whole error message, because have incorrect encoding

            jsulmJ 1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Hi,

              Since these options are per channel, why not let your Channel objects manage them ?

              You could add a getter to your Channel object to return their options and a setter to your dialog where you pass a list of Options object that are coming from your Channel objects. So if you add a new channel you don't need to modify your dialog.

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              2
              • A Andrey Shmelew

                @jsulm
                sorry, i can not post whole error message, because have incorrect encoding

                jsulmJ Offline
                jsulmJ Offline
                jsulm
                Lifetime Qt Champion
                wrote on last edited by
                #7

                @Andrey-Shmelew Is it this one: https://msdn.microsoft.com/de-de/library/2s2d2tez.aspx ?
                You can still post in Russian some of us can read and understand it :-)
                And please post more code not only that debug line, so we can better understand what you are doing.

                https://forum.qt.io/topic/113070/qt-code-of-conduct

                A 1 Reply Last reply
                2
                • jsulmJ jsulm

                  @Andrey-Shmelew Is it this one: https://msdn.microsoft.com/de-de/library/2s2d2tez.aspx ?
                  You can still post in Russian some of us can read and understand it :-)
                  And please post more code not only that debug line, so we can better understand what you are doing.

                  A Offline
                  A Offline
                  Andrey Shmelew
                  wrote on last edited by
                  #8

                  @jsulm
                  this is a code

                      QList<ChannelOptions> ChannelOptionsList;
                      ChannelOptions tempoptions1;
                      tempoptions1.SetUnitsName("Ampers");
                      ChannelOptionsList.append(tempoptions1);
                      qDebug() << ChannelOptionsList.at(0).GetUnitsName();
                  

                  this is an error
                  alt text

                  i put ChannelOptions options1; and ChannelOptions options2; in .h file,
                  now it seems to be working

                  jsulmJ 1 Reply Last reply
                  0
                  • A Andrey Shmelew

                    @jsulm
                    this is a code

                        QList<ChannelOptions> ChannelOptionsList;
                        ChannelOptions tempoptions1;
                        tempoptions1.SetUnitsName("Ampers");
                        ChannelOptionsList.append(tempoptions1);
                        qDebug() << ChannelOptionsList.at(0).GetUnitsName();
                    

                    this is an error
                    alt text

                    i put ChannelOptions options1; and ChannelOptions options2; in .h file,
                    now it seems to be working

                    jsulmJ Offline
                    jsulmJ Offline
                    jsulm
                    Lifetime Qt Champion
                    wrote on last edited by
                    #9

                    @Andrey-Shmelew But if you use a list now, why do you have options1 and options2 in your header then?
                    The problem you had before (C2662) was: QList::at returns a CONST reference and you're trying to call a non-const method on it, this is forbidden. Use [0] instead of at(0)

                    https://forum.qt.io/topic/113070/qt-code-of-conduct

                    A 1 Reply Last reply
                    1
                    • jsulmJ jsulm

                      @Andrey-Shmelew But if you use a list now, why do you have options1 and options2 in your header then?
                      The problem you had before (C2662) was: QList::at returns a CONST reference and you're trying to call a non-const method on it, this is forbidden. Use [0] instead of at(0)

                      A Offline
                      A Offline
                      Andrey Shmelew
                      wrote on last edited by Andrey Shmelew
                      #10

                      @jsulm

                      Use [0] instead of at(0)

                      Thank you, works fine. The other variant with options1 and options2 in .h file also works.

                      I think, the problem is solved now, thanks to all

                      1 Reply Last reply
                      1

                      • Login

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