PDA

View Full Version : QFile and drawText()



seniorc
27th March 2014, 19:41
Hello,

I have a problem qfile.Here is my code:


void Graph::readWrite(const QString &fileLoca){
QFile inFile(fileLoca);

if(inFile.open(QIODevice::ReadWrite | QIODevice::Text)){

QTextStream in(&inFile);
source = in.readLine();
while(!in.atEnd()){
QString v,m;
QString line = in.readLine();
double price;
v = str_split(line,'-');
m = str_split(line,':');
price = line.toDouble();
this->addEdge(v,m,price);
}

in << endl << "cost : " << kruskal();
inFile.close();

}

}

line 18 "endl" not working and my file failing.for example here is my file.

D
A-B:2
A-D:5
A-F:6
B-C:8
B-D:6
C-D:3
C-E:5
D-E:6
D-F:7
E-F:2

and i want this

D
A-B:2
A-D:5
A-F:6
B-C:8
B-D:6
C-D:3
C-E:5
D-E:6
D-F:7
E-F:2
cost : 17

but i see this

DA-B:2A-D:5A-F:6B-C:8B-D:6C-D:3C-E:5D-E:6D-F:7E-F:2cost : 17

What is my problem ?

and my second problem i'm working draw text on my graphic screen and i use qpainter class and drawText().
I have two point and string so i used drawtext(QPointF(x,y),string) and this func. begin write (x,y) point but i want (x,y) point is my string center point.How can i do this.

Thanks.

anda_skoa
30th March 2014, 11:51
What is my problem ?

Have you tried


in << "\ncost : " << kruskal();




and my second problem i'm working draw text on my graphic screen and i use qpainter class and drawText().
I have two point and string so i used drawtext(QPointF(x,y),string) and this func. begin write (x,y) point but i want (x,y) point is my string center point.How can i do this.


Use QFontMetrics to get the bounding rect for the text you want to draw, move the center to the point, use one of the drawText() overloads that allows you to specify flags, specify Qt::AlignCenter

Cheers,
_