0

I have some QCheckBox named from "cb0" to "cb11". Why get I an error, trying this, or why if thats the reason would it accept no std::strings?

using namespace std

for(int i = 0; i < 12; i++){
   ostringstream strs;
   strs << i;
   string k = "cb" + strs.str();

   QCheckBox *cb = findChild<QCheckBox*>(k);
   ...
}
Jonas
  • 6,915
  • 8
  • 35
  • 53
Karl Cegel
  • 27
  • 4
  • 1
    I would just use a QString for that (making use of QString::arg()). Although it would help your question if you put whatever error you have in your question as text. I have no idea what error you have. – drescherjm Jan 19 '17 at 17:40
  • If you are getting a compiler error you should include it. – NathanOliver Jan 19 '17 at 17:41
  • Replace `QCheckBox *cb = findChild(k);` with `QCheckBox *cb = findChild(QString("cb%1").arg(i));` Why are you doing `i+1` when your combo boxes are cb0 ... cb11? – drescherjm Jan 19 '17 at 17:43
  • thanks, i+1 is anly a kind of typo, cause thats not my actual code – Karl Cegel Jan 19 '17 at 18:06
  • If you want it to accept std::string you probably have to use `QCheckBox *cb = findChild(QString::fromStdString(k));` http://stackoverflow.com/questions/1814189/how-to-change-string-into-qstring – drescherjm Jan 19 '17 at 18:25

0 Answers0