How to properly keep settings for 20 identical signal channels

  • 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


    class ChannelOptions
        static int count222;
    public :  int count;
        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
        int signaltype;
        int lowerlimit;
        int higherlimit;
        int lowermeasurelimit;
        int highermeasurelimit;
        int measureperiodsecond;
        QString unitsname;

    Have methods:


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

    Have UI form called Options.


    Options::Options(QWidget *parent) :
        ui(new Ui::Options)
        connect(ui->UnChan1RadButOtkl, SIGNAL(pressed()), this, SLOT(checkboxchange()) );
        // параметры для каждого канала
        ChannelOptions options1;
        ChannelOptions options2;
        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()
        qDebug() << options1.GetUnitsName();

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

  • Qt Champions 2017

    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;


    qDebug() <<;

  • @mrjj
    Thanks, but
    qDebug() <<;
    returns error C2662

  • Moderators

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

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

  • Lifetime Qt Champion


    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.

  • Moderators

    @Andrey-Shmelew Is it this one: ?
    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.

  • @jsulm
    this is a code

        QList<ChannelOptions> ChannelOptionsList;
        ChannelOptions tempoptions1;
        qDebug() <<;

    this is an error
    alt text

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

  • Moderators

    @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)

  • @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

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.