Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Working with C++ code with QT Libraries, Read .txt File
Forum Update on Monday, May 27th 2025

Working with C++ code with QT Libraries, Read .txt File

Scheduled Pinned Locked Moved General and Desktop
1 Posts 1 Posters 844 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    vitaR
    wrote on 27 Mar 2014, 16:17 last edited by
    #1

    Hi, I'm having a problem with a project.

    In this project I have to read some values from a .txt file, and then I have to deploy some images in a window.
    I have to count every line (row) of this .txt file and colums, to show a maze with images. But Seems that my function to read this values is not working, so I guess it have to be some kind of compatibility between c++ code and QT code.

    There's the code:

    1. To read the size of the maze and create it.
      @void Window::tamMat(){
      fstream inFile;
      int num;
      n=m=0; //attributes of the Window Class
      inFile.open("mat.txt",ios::in);
      string line;

    getline(inFile,line);
    stringstream temp(line);
    while(temp >> num)
    m++;
    n++;
    while(getline(inFile,line))
    n++;
    inFile.close();
    mat = new int*[n];
    for(int i=0;i<n;i++)
    mat[i]=new int[m]; //mat is a bidimensional array, I'm creating the size with the values I count from the .txt file
    this->show();
    }@

    2)(TESTING ONLY) Try to Show in the frame 'n' numbers of images, with the value that got 'n' in the tamMat() function.
    @void Window::load(){
    container = new QWidget();
    QPixmap icon("E:/Data/Pictures/PixelArt/Limon.png");
    QPixmap icon2("E:/Data/UNET/EstructuraDeDatos/Qt/NewOne/Image/Background.png");
    QGraphicsScene *scene = new QGraphicsScene();
    scene->setSceneRect(0.0,0.0,800.0,600.0);
    for(int i=0;i<this->n;i++){
    QGraphicsPixmapItem image = new QGraphicsPixmapItem();
    image->setPixmap(icon);
    scene->addItem(image);
    image->setPos(i
    icon.width(),0);
    }
    QTransform transform;
    QGraphicsPixmapItem image2 = qgraphicsitem_cast<QGraphicsPixmapItem>(scene->itemAt(180,0,transform));
    scene->addItem(image2);
    QGraphicsView *view = new QGraphicsView();
    view->setScene(scene);
    view->show();
    }@

    The thing is that seems that the int value 'n', Still zero(0), cause there's no image in this frame. So the for loop, never happen (check load() Function).
    I don't know if I can't work with C++ library while I'm working with the QT Ones. Could be this the problem?

    Thanks for your time. By the way, I have to work with some functions in c++ code, like fstream library, work with data structures, like piles, some kind of that stuff, any advice you can give me to avoid future errors, would be great, thanks.

    1 Reply Last reply
    0

    1/1

    27 Mar 2014, 16:17

    • Login

    • Login or register to search.
    1 out of 1
    • First post
      1/1
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved