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#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
-
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();
-
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();
@mrjj
Thanks, but
qDebug() << ChannelOptionsList.at(0).GetUnitsName();
returns error C2662 -
@mrjj
Thanks, but
qDebug() << ChannelOptionsList.at(0).GetUnitsName();
returns error C2662@Andrey-Shmelew Did you add any ChannelOptions to the list?
And you should post the whole error message not only its id. -
@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 -
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.
-
@jsulm
sorry, i can not post whole error message, because have incorrect encoding@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. -
@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.@jsulm
this is a codeQList<ChannelOptions> ChannelOptionsList; ChannelOptions tempoptions1; tempoptions1.SetUnitsName("Ampers"); ChannelOptionsList.append(tempoptions1); qDebug() << ChannelOptionsList.at(0).GetUnitsName();
this is an error
i put ChannelOptions options1; and ChannelOptions options2; in .h file,
now it seems to be working -
@jsulm
this is a codeQList<ChannelOptions> ChannelOptionsList; ChannelOptions tempoptions1; tempoptions1.SetUnitsName("Ampers"); ChannelOptionsList.append(tempoptions1); qDebug() << ChannelOptionsList.at(0).GetUnitsName();
this is an error
i put ChannelOptions options1; and ChannelOptions options2; in .h file,
now it seems to be working@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) -
@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)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