Results 1 to 2 of 2

Thread: QFile and drawText()

  1. #1
    Join Date
    Dec 2013
    Posts
    20
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QFile and drawText()

    Hello,

    I have a problem qfile.Here is my code:

    Qt Code:
    1. void Graph::readWrite(const QString &fileLoca){
    2. QFile inFile(fileLoca);
    3.  
    4. if(inFile.open(QIODevice::ReadWrite | QIODevice::Text)){
    5.  
    6. QTextStream in(&inFile);
    7. source = in.readLine();
    8. while(!in.atEnd()){
    9. QString v,m;
    10. QString line = in.readLine();
    11. double price;
    12. v = str_split(line,'-');
    13. m = str_split(line,':');
    14. price = line.toDouble();
    15. this->addEdge(v,m,price);
    16. }
    17.  
    18. in << endl << "cost : " << kruskal();
    19. inFile.close();
    20.  
    21. }
    22.  
    23. }
    To copy to clipboard, switch view to plain text mode 

    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.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QFile and drawText()

    Quote Originally Posted by seniorc View Post
    What is my problem ?
    Have you tried
    Qt Code:
    1. in << "\ncost : " << kruskal();
    To copy to clipboard, switch view to plain text mode 

    Quote Originally Posted by seniorc View Post
    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,
    _

Similar Threads

  1. Replies: 2
    Last Post: 6th May 2013, 08:06
  2. Replies: 4
    Last Post: 9th May 2011, 09:52
  3. QFile &QFile::operator= is private
    By Fallen_ in forum Newbie
    Replies: 1
    Last Post: 15th March 2011, 15:08
  4. DrawText ?
    By whitefurrows in forum Qt Programming
    Replies: 2
    Last Post: 14th February 2007, 21:08
  5. drawText
    By pwqiang in forum Qt Programming
    Replies: 1
    Last Post: 19th December 2006, 08:52

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.