How to load a map in QT GUI application using text file
Hi everybody I wanted load a map in y GUI application
for example::
0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 1 1 0 1 1 0 0 0 0 0 0 0
1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1
A 0 denotes a draw nothing and 1 denotes a draw rectangle
Now how to open a .txt file in Qt GUI application....and how to access the every 0 & 1 ..so that I can draw a rectangle whenever the 1 is encountered and draw nothing whenever 0 is encountered ...please help as I have posted this to load simple Map using text files
Re: How to load a map in QT GUI application using text file
What have you done so far to solve your problem? What exactly are you having problems with?
Re: How to load a map in QT GUI application using text file
Actually i have no clue how to read a text file in qt creator ,,,,,,and the C++ method of ifstream is not working???is there any method to read a text file in qt creator...
and secondly I am going to use for loop to read each element in the text file and I have no Idea where to stop the loop
Code:
for(int i=0;i<??;i++)
{
for(int j=0;j<??;j++)
{
if (map.tile[y][x] != 0)
{
drawImage(brickImage, x * TILE_SIZE, y * TILE_SIZE);
}
}
}
Re: How to load a map in QT GUI application using text file
Why isn't the std::ifstream approach working? Post your code and an explanation of the problem.
Re: How to load a map in QT GUI application using text file
I tried this on my GUI application ....Actually it should load the content of input.txt file in textedit when I clicked the button....but result does not come.ie the the text file is not loaded...and no errors are observed
Code:
void MainWindow::on_pushButton_clicked()
{
while (!in.atEnd())
{
line = in.readAll();
ui->textEdit->setPlainText(line);
}
file.close();
}
Re: How to load a map in QT GUI application using text file
Why don't you check that the file actually gets opened?
Re: How to load a map in QT GUI application using text file
I again tried to display my text file in ...but now in textbrowser...this time my program ran succcessfully and I and i browsed to my text file and it did displayed the content of my textfile but..ERROR::only single line is diplayed....please suggest me ...to improve my code
Code:
void MainWindow::on_pushButton_clicked()
{
QString filename
= QFileDialog::getOpenFileName(this, tr
("wew"),
"",tr
("allfiles(*.txt)"));
{
while (!in.atEnd())
{
line = in.readLine();
ui->textBrowser->setText(line);
//ui->textEdit->setPlainText(line);
}
file.close();
}
}
Re: How to load a map in QT GUI application using text file
can you explain (in own words!) what happens in this snippet?
Code:
while (!in.atEnd())
{
line = in.readLine();
ui->textBrowser->setText(line);
}
Re: How to load a map in QT GUI application using text file
Ok I got it correct!!!
U don't know how to load a map using text file in qt creator
Re: How to load a map in QT GUI application using text file
Quote:
Originally Posted by
jerkymotion
can anybody please help me to load map in qt creator
Sure. Launch QtCreator, from the "File" menu choose "Open file or project" and then browse until you see the file containing your map, select it and click on "Open". Your map should be opened in Qt Creator now.
Re: How to load a map in QT GUI application using text file
that's funny
actually I was asking about how to load a map using text file in qt creator????
Re: How to load a map in QT GUI application using text file
wysota might explode soon :)
jerkymotion, if you mean qt creator then he is right. If you mean Qt, then look at what felixB asked you and think about what you are doing there! It is the reason you are getting your result.
Re: How to load a map in QT GUI application using text file
why do you want to load such a map in Qt Creator?
Re: How to load a map in QT GUI application using text file
Quote:
Originally Posted by
jerkymotion
that's funny
actually I was asking about how to load a map using text file in qt creator????
Is this your school project, a daily job project or a free-time project?
Re: How to load a map in QT GUI application using text file
Ok it's my school project
I wanted load a map for navigation purpose....so that if i clicked in the map it gives the co-ordinate value of that position and I want to send those value to my serial port...that's it
so I had an idea about loading a map via text file but I am finding it difficult in qt because I am newbie to Qt creator
Re: How to load a map in QT GUI application using text file
Quote:
Originally Posted by
jerkymotion
Ok it's my school project
We have a rule on this forum that we can't give full solutions to school projects. We can only help you go in the right direction.
Quote:
so I had an idea about loading a map via text file but I am finding it difficult in qt because I am newbie to Qt creator
Your approach with QFile looked correct but you dropped it for some reason. Maybe try going back to it and expand it. Think about an algorithm for reading the map. If necessary, take a piece of paper and a pencil and "emulate" the process or reading a file.