Welcome! Log In Create A New Profile

Advanced

Path Settings

Posted by AndreB 
Announcements Last Post
Announcement SoC Curricula 09/30/2017 01:08PM
Announcement Demarcation or scoping of examinations and assessment 02/13/2017 07:59AM
Announcement School of Computing Short Learning Programmes 11/24/2014 08:37AM
Announcement Unisa contact information 07/28/2011 01:28PM
Path Settings
August 04, 2009 12:41PM
I've just had to re-install and configure QT on my laptop today, as I have a new hard drive (the old one crashed, again).
Everything seems fine, and I even got the Dataobjects and Utils.dll's to compile correctly. However, my problem is this:
When testing my solution to Question 5 of Assignment 1 in debug (from QIde), the file specified in the cmd line param -i Discounts.txt is simply not found.
The cmd line arg is picked up fine (i.e. the ArgumentList class from Utils.dll is working fine), and the filename is passed correctly to the function that tests if it exists and reads the file. However the test to see if the file exists fails.
Now, if I run this outside of QIde, from the cmd prompt, then it works fine, the file is found and the discounts read correctly - but just not within QIde unless I pass the absolute file path as the argument.
I have made sure that the Working Directory variable is blank to ensure that the Project directory is used.

Any ideas????
Anonymous User
Re: Path Settings
August 05, 2009 11:13PM
Hi Andre, I think that while Qt is setup, your QIde needs tweaking. I couldn't be assed to reconfigure Ezust's class using LD_LINKER so I wrote my own class to deal with file IO. I'll hook it up to the gui using a command pattern. My code so far (2 glasses of wine, half measure of guilt, 15 minutes):
Language: C++ (QT)
#ifndef WRITER_H #define WRITER_H #include <QString> #include <QFile>   class Writer { public: Writer(); void writeIt(QString string); void readIt(QString file); private: QString string; };   #endif // WRITER_H   #include "writer.h" #include <QTextStream> #include <QtDebug>   Writer::Writer(){   } void Writer::writeIt(QString s){ QFile file("file.txt"); if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) return; QTextStream out(&file); out << "The magic number is: " << s << "\n"; }   void Writer::readIt(QString file){ QFile fileName(file); if (!fileName.open(QIODevice::ReadOnly | QIODevice::Text)){ qDebug()<<"no file found"<<endl; return; }     QTextStream in(&fileName); while (!in.atEnd()) { string = in.readLine(); } qDebug()<<string<<endl; }

hope this helps smiling smiley
Re: Path Settings
August 06, 2009 01:48PM
Thanks Rick - not exactly though.
My code for reading the file is 100%, but QIde is simply not finding the path to the file if the parameter is not passed as an absolute path.
That is, when debugging, if I add the parameter -i Discounts.txt, then the file is not found. However if I pass the parameter as -i C:\Qt\MyCode\Assign01\Question5\Debug\Discounts.txt then the file is found no problem.
If I run the executable outside of QIde, either from the command prompt or from a configured shortcut, then I have no problem with only providing -i Discounts.txt as the param.
Anonymous User
Re: Path Settings
August 06, 2009 03:28PM
That's why I rolled my own grinning smiley
avatar Re: Path Settings
August 06, 2009 10:52PM
Then your working directory is different when running from QIDE
Re: Path Settings
August 07, 2009 11:21AM
That's what I figured but you'd expect the default to be the application's debug directory if you haven't specified anything else.
avatar Re: Path Settings
August 07, 2009 01:28PM
Try outputting QCoreApplication::applicationFilePath(). That will tell you exactly where the file is running from. See if there's a difference between running through QIDE and running from the console.
Re: Path Settings
August 08, 2009 04:03AM
Thanks Rob - will give it a go.
Anonymous User
Re: Path Settings
August 08, 2009 01:41PM
If you read the tut letter, you'll come across this :
Quote

You must create a zipped file containing only your source code. This should not include any executable files, compiled object files or automatically generated files.
This means that while you'll be able to link Ezust's code into yours, you'll have to hope that the lecturer's config is the same as yours, else your code will not compile on the lecturer's machine. Compilation is the first criteria to grading your assignment.
I think that implementing your own writer class is a safer option in this respect. You are guaranteed compilation.
avatar Re: Path Settings
August 08, 2009 03:16PM
I'm of the general opinion that writers of textbooks tend to write half-baked, usually buggy code. I've found this to be true of all the C++ courses I've done so far at Unisa. Hence, I'm writing using the standard Qt classes and my own. I'm not relying on any other stuff. If I need similar functionality to what's done by the authors, I'll create my own classes.
Anonymous User
Re: Path Settings
August 08, 2009 04:07PM
lol, Rob.
I'm going to go one step further and chuck the .dat files out altogether. Check this out:
http://www.digitalfanatics.org/projects/qt_tutorial/chapter09.html
avatar Re: Path Settings
August 19, 2009 10:25PM
Hello,

For assignment 3, how are you specify the file paths to items.dat and transaction.dat?

Are you putting the files in the same directory as the exe?
Or is it in the same directory as the source code?
Or is this at some specific location?

Not sure what will be best so that when I upload my assignment the lecturers don't have too many issues confused smiley
Re: Path Settings
August 19, 2009 10:34PM
I have it as "Datafiles/items.dat" where Datafiles is a new directory on the root of my project. Still need to test this on another computer to check that it works.

If you don't want to cause issues, I suggest leaving everything on the root *like they've been doing al this time*
avatar Re: Path Settings
August 19, 2009 10:51PM
Hi Anita,

Your method works when you run it from within QIDE or QDevelop but when you run the application outside of the development environment, you're likely going to run into the same problems listed at the top of this post.

I've opted to create a header file with constants for the filenames. The app will use these constants and if the lecturers have problems with it they can change it to whatever the like.
I think a better solution would have been to ask the user to specify the working directory using a settings window or something similar but alas its too late now to get all fancy.
Re: Path Settings
August 20, 2009 12:11AM
damn, you are right..
*sighs, and sets off to fix the new problem*

The question is - are they going to build the app, and then run the exe, or will they run it through QIde??
Re: Path Settings
August 20, 2009 10:46AM
This works inside the ide, and from command prompt

Language: C++ (QT)
QFile file("../DataFiles/items.dat"); //location from cmd   if( !file.exists() ){ file.setFileName("DataFiles/items.dat"); //location from inside ide }   if (file.exists() ){ cout << "file found" << endl; //do what you need to do }

Hope this helps
Anonymous User
Re: Path Settings
August 20, 2009 11:13AM
interesting that Qt can determine the slash directory separator ('\' or '/'winking smiley depending on the platform. I think there were issues with that in Qt4.1 and that it was only fixed in > Qt 4.2.
Are you sure that '/' will work under windows using 4.1?
Re: Path Settings
August 20, 2009 11:34AM
I'm using 4.1.1... confused smiley
Anonymous User
Re: Path Settings
August 20, 2009 11:39AM
oh ok. My bad then smiling smiley
Sorry, only registered users may post in this forum.

Click here to login