Results 1 to 2 of 2

Thread: How to read text file and draw line help.

  1. #1
    Join Date
    Feb 2015
    Posts
    4
    Qt products
    Platforms
    Unix/X11

    Default How to read text file and draw line help.

    my data in text file like this
    1.5
    2.0
    1.23
    2.67

    I would like to drawline vertical axis.Now i have no idea plz.
    my code.
    Qt Code:
    1. #include "dialog.h"
    2. #include "ui_dialog.h"
    3. #include<QPainter>
    4. Dialog::Dialog(QWidget *parent) :
    5. QDialog(parent),
    6. ui(new Ui::Dialog)
    7.  
    8. {
    9.  
    10. ui->setupUi(this);
    11. // bool w_flag = false;
    12. }
    13.  
    14. Dialog::~Dialog()
    15. {
    16.  
    17. delete ui;
    18. }
    19. void Dialog::on_pushButton_2_clicked()
    20. {
    21.  
    22. m_fill = !m_fill;
    23. readfile();
    24. update();
    25.  
    26. }
    27.  
    28. void Dialog::paintEvent(QPaintEvent *e)
    29. {
    30.  
    31. QPainter painter(this);
    32. if(m_fill)
    33. {
    34. painter.setPen( QPen(Qt::red, 2,Qt::SolidLine) );
    35. painter.drawLine( 300, 300, 800,300);
    36. }
    37.  
    38. }
    39. void Dialog::readfile()
    40. {
    41. QString filename1 = "data.txt";//readfile
    42. QFile file1(filename1);
    43. file1.open(QIODevice::ReadOnly|QIODevice::Text);
    44. QTextStream in(&file1);
    45. QString init = in.readLine();
    46.  
    47. file1.close();
    48. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by anda_skoa; 5th February 2015 at 08:47. Reason: missing [code] tags

  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: How to read text file and draw line help.

    Well, you are drawing a horizontal line already, a vertical line is very similar: both points have the same x coordinates and different y coordinates.

    Cheers,
    _

Similar Threads

  1. Replies: 7
    Last Post: 30th November 2013, 14:27
  2. Replies: 8
    Last Post: 8th May 2012, 09:39
  3. Replies: 1
    Last Post: 18th January 2012, 09:28
  4. Read gzip file line-by-line
    By The_Fallen in forum Qt Programming
    Replies: 4
    Last Post: 6th September 2011, 13:41
  5. How to read line number in a text file
    By grsandeep85 in forum Qt Programming
    Replies: 7
    Last Post: 31st July 2009, 09:09

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.