How to get common element from a group of QStringList?
-
Hi all,
I have problem, in my program i'm using a hash variable
QHash<QString,QStringList> HFileSignal;
It is a hash of file name and signal name list inside the file.
Now i want to find common signals from al those file.So kindly tell me
- Is there any buit in function in Qt to achieve this?
2.How can i declare a variable name on fly(while running program, inside a loop i must able to declare the variable)?
- Is there any buit in function in Qt to achieve this?
-
@1
Easiest would be to convert each contained QStringList into a QSet<QString>, and then use QSet::intersect() to get the intersection (shared elements) of these sets.@2
Get yourself a C++ book, and think logically about what a variable is, what role it plays, and what the role of the compiler is. -
[quote author="Andre" date="1326093083"]
@2
Get yourself a C++ book, and think logically about what a variable is, what role it plays, and what the role of the compiler is. [/quote]Thank u Andre....
About my 2nd question...
I meant to say... in a loop i want to create variables like var1,var2, var3.......varN, depending on certain count, that count is again variable....How can i do that? -
You don't. You can not declare variables-with-variable-names at runtime. At least, not in a compiled language like C++. Think about it: when would the compiler get to see those variables exactly?
I think you need a data structure like a QVector, but we can only guess because you don't tell us what you need. However, this is really where some basic C++ knowledge comes in. I am serious: get yourself a good C++ book and use that to learn about the structure of C++ applications, data structures, pointers, etc.