How to get the "text" from checkbox?
Hi. My english is not good, but I hope you understand me. :p
I have many checkboxes, each with a different name (checkBox_1, checkBox_2, 3, 4 etc) and different text. I want get that text and then put it in the html file. Of course, depending on whether it is selected.
Code:
tresc = ui->checkMocne_1->text();
fp.write(tresc);
fp.close();
Not working. :<
I do not know how to do it, any ideas? :confused:
Re: How to get the "text" from checkbox?
You code looks correct, QCheckBox::text() should work for you.
Re: How to get the "text" from checkbox?
Re: How to get the "text" from checkbox?
You are not writing text in the file, the open code should look like:
also you might want to check (with an if) if the file was opened successfully.
QFile documentation
Re: How to get the "text" from checkbox?
Still does not work. I do not know how well I do it, can I get the text from the text label checkbox?
Re: How to get the "text" from checkbox?
Is tresc a QString or what type is it?
And please give us more information, define "doesn't work".
You can try to print (on screen using qDebug() ) the tresc and see if that is the problem there or in other parts, also did you check if the file is opened for writing?
And if tresc is a QString then use a QTextStream to write the QString to file (see the small example in the documentation link i gave you in the previous post)
Re: How to get the "text" from checkbox?
Code:
QString str
=ui
->chk1
->currentItem
()->text
();
I think this will work definitely>.
Re: How to get the "text" from checkbox?
Does the file get created? Does it contain anything? The code is definitely correct.
Re: How to get the "text" from checkbox?
Okay, my errors look. :confused:
http://i52.tinypic.com/5af1fq.png
http://i51.tinypic.com/2lm5f7b.png
Quote:
Originally Posted by
Zlatomir
Is tresc a QString or what type is it?
Yep. QString
@wysota - zauważyłem, że jesteś z Warszawy. Być może mój angielski ogranicza komunikacje :p Chodzi o to, że chcę pobrać text label danego checkboxa do zmiennej, aby następnie umieścić go w pliku html. Przykład checkbox o nazwie checMocne_1 o label: "stosuje się do norm społecznych" - no i w zależności czy checkbox jest zaznaczony chcę pobrać ten label i umieścić go w w jakimś miejscu pliku html.
Re: How to get the "text" from checkbox?
You can use QTextStream :
Code:
{
out << ui->checkMocne_1->text();
f.close();
}
Re: How to get the "text" from checkbox?
Re: How to get the "text" from checkbox?
Alan_K, you do realize that the answer was just in front of you?
And that the problem was not what you said it was?
And that, next time, you need to say more information about what is not really working (compile/run error, implicated code, type of variables, etc), else everything we can do is guessing.