QMapIterator declaration of several lists problem - qt

i'm having 3 types of lists, and i'm trying to print them according to attribute_type.
so according attribute_type the iterator is chosen.
the problem is if for example attribute_type == "pis", the if condition is executed but when finished it returns to the upper decleration: QMapIterator it(pit.item_parameters), so this way the iterator is not valid...
how should i declare it properly ?
QMapIterator<QString, IP> it(pit.item_parameters);
if (attribute_type == "ips") {
QMapIterator<QString, IP> it(pit.item_parameters);
if (pit.item_parameters.isEmpty()) { return; }
}
else if (attribute_type == "variables") {
QMapIterator<QString, Variable> it(pit.variables);
if (pit.variables.isEmpty()) { return; }
}
else if (attribute_type == "pis") {
QMapIterator<QString, PI> it(pit.pis);
if (pit.pis.isEmpty()) { return; }
}
while(it.hasNext())
{
it.next();
text += it.key();
text += it.value().type;
}

If your types IP, PI and Variable derive from the same class ParentClass having type as public member, you can declare it that way:
QMapIterator<QString, ParentClass> it;

Related

printf("%s",stringName) prints the wrong text but only once

I have a menu function, in which I input a question and two options, then the user choses one. It works just fine everytime but one ; I call
if (menu("ou est le corps?","interieur ","exterieur")==1)
{
but instead of printing "interieur " It shows "p?"
it works just fine without the space, but I need to make a space and \n does quite the same thing.
I have another call of this function, with \n which works fine so I have no idea about why this wouldn't work. Anyone has got an idea?
PS : the value of choix1 is then sent via bluetooth, and there it stays intact.
PPS : tell me if something is unclear, I'm not naturally english
PPPS(sorry) : tried to run the same code again, it seems to print a random character followed by "?", I had twice "p?", once "?" and once " '?"
[updates] once "#?"
int menu (String texte, String choix1, String choix2)
{
envoye = 0;
rxValue = "0";
while (digitalRead(M5_BUTTON_HOME) != LOW && rxValue == "0")
{
heure();
M5.Lcd.setTextSize(2);
M5.Lcd.print(texte);
M5.Lcd.printf("\n");
if (selec == 0)
{
M5.Lcd.printf("->%s %s", choix1, choix2);
}
else
{
M5.Lcd.printf(" %s ->%s", choix1, choix2);
}
if (M5.BtnB.read() != 0)
{
if (selec == 0)
{
selec = 1;
}
else
{
selec = 0;
}
while (M5.BtnB.read() != 0)
{
if(digitalRead(M5_BUTTON_HOME) == LOW)
{
M5.Lcd.fillScreen(BLACK);
delay(1000);
if(digitalRead(M5_BUTTON_HOME) == LOW)
{
choix=50;
heure();
delay(1000);
return 1;
}
}
}
}
if (deviceConnected && envoye == 0)
{
sendchoix(texte, choix1, choix2);
envoye++;
}
}
if (rxValue != "0")
{
recuble = &rxValue[0];
selec = atoi(recuble) - 1;
rxValue = "0";
}
M5.Lcd.fillScreen(BLACK);
delay(300);
return selec;
}
int menu (String texte, String choix1, String choix2) {
[...]
M5.Lcd.printf("->%s %s", choix1, choix2);
You cannot treat String objects as const char*, which is what the format specifier %s is expecting. String is an Arduino class for storing.. strings/character data, but an object of this class is not equivalent to the raw pointer to the data.
For that, you need to call the c_str() method on the String object to get the C-String pointer to the data, as shown in the documentation [1].
[..]
M5.Lcd.printf("->%s %s", choix1.c_str(), choix2.c_str());
[..]
[1] https://www.arduino.cc/reference/en/language/variables/data-types/string/functions/c_str/

How to use active() method x++

Ok I did it. It works fine. Thanks for help. Here is my code. Now I only need to call my command button in a differend form to disable it and create a info there. Anyone could look about it ? In my code I got reference errors.
[ExtensionOf(formdatasourcestr(ProdTableListPage, ProdTable))]
final class ProdParmReportFinishedActiveWG_Extension
{
public int active()
{
int ret;
next Active();
{
ProdTable tableBuffer = this.cursor();
ProdTable prodtable;
if(tableBuffer.ProdId == tableBuffer.CollectRefProdId
&& tableBuffer.ProdStatus != ProdStatus::ReportedFinished)
{
select firstonly RecId,ProdId from ProdTable where
ProdTable.CollectRefProdId == tableBuffer.ProdId
&& ProdTable.Prodstatus != ProdStatus::ReportedFinished
&& tableBuffer.RecId != prodtable.RecId;
{
Global::info(strFmt("%1 , %2",
prodtable.prodid, prodtable.recid));
// FormButtonControl mybutton = this.FormRun().design().controlname(formControlStr(ProdParmReportFinished, Ok)) as FormButtonControl;
// mybutton.enabled(false);
}
}
else
{
Global::info(strFmt("%1 , %2, %3, %4",
tableBuffer.prodid, tableBuffer.CollectRefProdId, tableBuffer.InventRefType, tableBuffer.ProdStatus));
}
}
return ret;
}
}
"I want to use this code everytime user changes his actual row but instead it runs just once and apply to all my rows."
Use the selectionChanged() method instead of active().
In fact most use cases where you think you should use active(), you're probably looking for selectionChanged() (or the OnSelectionChanged event for handlers) instead.

How do you pass different collections through the same parameter?

I am creating a method that will take a collection of different types (divs, spans..) and search it. I can't find a parameter to pass different collection types though. I tried IElementContainer and ElementCollections but I can't cast DivCollection to either. Is there another way?
The method that does the search:
private static ElementCollection searchCollections(IElementContainer ec, WACore.compStringInfo info)
{
if (info.componentIDName == WACore.componentIDs.Id.ToString())
{
return ec.Elements.Filter(Find.ById(info.componentIDValue));
}
else if (info.componentIDName == WACore.componentIDs.Name.ToString())
{
return ec.Elements.Filter(Find.ByName(info.componentIDValue));
}
else if (info.componentIDName == WACore.componentIDs.Title.ToString())
{
return ec.Elements.Filter(Find.ByTitle(info.componentIDValue));
}
else if (info.componentIDName == WACore.componentIDs.OuterText.ToString())
{
String str = info.componentIDValue.Substring(1, 6);
return ec.Elements.Filter(Find.ByText(new Regex(str)));
}
else
{
return null;
}
}
The caller(s):
return searchCollections((IElementContainer)doc.TextFields, info);
return searchCollections((IElementContainer)(doc.Divs), info);
return searchCollections((IElementContainer)doc.Spans, info);

How to use enum in if statement?

I have ASP.NET application and want to use enum in if statement.
I get variable in this way:
string choice = (string)Session["export_choice"];
if(choice == <here goes enum>)
{
}
else
{
}
enum can have 2 string values only.
this is normally where I would use a switch:
myEnumType myEnumChoice;
if (Enum.TryParse(choice, out myEnumChoice))
{
switch(myEnumChoice)
{
case myEnumType.FirstEnum:
//doSomething();
break;
case myEnumType.SecondEnum:
//doSomethingElse();
break;
}
}
else
throw new ArgumentException(string.Format("Unexpected enum value: {0}", choice));
use
EnumChoice choice = (EnumChoice) Enum.Parse(typeof(ChumChoice), (string)Session["export_choice"] , true);
EnumChoice is enum type
you can use it like
if(choice== EnumChoice.X)
{
}
else
{
}

How do I identify DirectShow audio renderer filters uniquely?

As I just found out the hard way, friendly names are not guaranteed to be unique. Bonus points if I can instantiate the filter from that identifier without having to enumerate them.
Renderer filters wrapping WaveOut devices can be identified by WaveOutId. Those wrapping DirectSound devices can be identified by DSGuid.
ICreateDevEnum* devices;
if (CoCreateInstance(CLSID_SystemDeviceEnum, NULL, CLSCTX_INPROC_SERVER, IID_ICreateDevEnum, (LPVOID*)&devices) == S_OK)
{
IEnumMoniker* enumerator;
if (devices->CreateClassEnumerator(CLSID_AudioRendererCategory, &enumerator, 0) == S_OK)
{
IMoniker* moniker;
while (enumerator->Next(1, &moniker, NULL) == S_OK)
{
IPropertyBag* properties;
if (moniker->BindToStorage(NULL, NULL, IID_IPropertyBag, (void**)&properties) == S_OK)
{
VARIANT variant;
VariantInit(&variant);
if (properties->Read(L"WaveOutId", &variant, NULL) == S_OK)
{
// variant.lVal now contains the id of the wrapped WaveOut device.
}
else if (properties->Read(L"DSGuid", &variant, NULL) == S_OK)
{
// variant.bstrVal now contains an uppercase GUID.
// It's the same GUID you would get from DirectSoundEnumerate.
}
VariantClear(&variant);
properties->Release();
}
moniker->Release();
}
enumerator->Release();
}
devices->Release();
}

Resources