Nominate our 2022 Qt Champions!

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

  • 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"mat.txt",ios::in);
      string line;

    stringstream temp(line);
    while(temp >> num)
    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

    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();
    for(int i=0;i<this->n;i++){
    QGraphicsPixmapItem image = new QGraphicsPixmapItem();
    QTransform transform;
    QGraphicsPixmapItem image2 = qgraphicsitem_cast<QGraphicsPixmapItem>(scene->itemAt(180,0,transform));
    QGraphicsView *view = new QGraphicsView();

    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.

Log in to reply