PDA

View Full Version : Listing points in TextEdit



mattis16
9th June 2011, 07:56
I've got a console program representing points on the plane and now i want to the window program (on linux). I have done button "List points" and i want it to write them in QPlainTextEdit (unless there isn't a better option). In console program i listed this points using function:

cout << set1
Is it possible to do it in qt?

Santosh Reddy
9th June 2011, 08:18
Yes it is possible in Qt.

This should be simple, if you know how to create a basic QWidget based GUI, and add standard display widgets to it

mattis16
9th June 2011, 08:26
I'm beginner and i don't know how to do that, but i have to this today :/
I forgot to attach operator << overloading:

std::ostream& operator<< (std::ostream& os, const Set& st)
{
if (st.size() == 0) os << "NULL";
for (long i=0; i<st.size(); i++)
{
if ((i%5 == 0)) os << std::endl;
os << st[i] << ", ";
}
os << std::endl;
return os;
}

Could you help me with it?

wysota
9th June 2011, 08:35
If this is a school project then we can't help you much, otherwise you will not learn. I can give you a hint that dumping those points to a text edit box is not better than dumping them to a console. It would be more interesting if you drawn a graphical representation of those points or at least if you displayed the points in a list (such as QListWidget).

mattis16
9th June 2011, 08:38
It's not a school project. I'm helping my friend with c++ and i'm stuck only with it... He has tomorrow a test and i have to explain it to him.
This points have to be listed, not drawn on the plot.

Santosh Reddy
9th June 2011, 08:53
Follow this post, it might of some use to you
http://www.qtcentre.org/threads/41533-QTextEdit-from-cout-stream-not-displayed-at-once

mattis16
9th June 2011, 10:31
Thanks.
I've made something like that

void Surface::write(const Set& st)
{
QString output;
for (long i=0; i<st.size(); i++)
{
if (i%5 == 0) {
Main->appendPlainText(output);
output.clear();
}else{
output.append(QString::number(st[i]) + ", ");
}
}
}
and put it into set.cc (supporting class Set from set.h) and i've got an error:

/home/matthew/Dewsktop/QT Project/QT-build-desktop/../QT/Set.cc:176: error:no matching function for call to ‘QString::number(Surface)’

What should i do to get rid of that error?