Active Topics

 


Reply
Thread Tools
Posts: 7 | Thanked: 0 times | Joined on Feb 2011
#1
Hi Everyone!

I am newcomer in programming Qt for my N900.

I am writing little first-step-applications for my N900. Everything worked fine till now. I already have own applications for the device, but non of them uses an external data file.

Now I am trying to create an application for my N900 which uses an external .txt file. The package is created successfully, the application is installed successfully, however the binary does not see the .txt (maybe it is not in the package?).

Something is wrong with the package, I think.

I am using MADDE Developer 0.6.72 to create the project skeleton.
I am using Qt creator for create the code. After once the code is created successfully then I am running the following commands in MADDE Developer 0.6.72 for the updated skeleton folder created above.

I writed the following lines into MADDE developer:

<<
//create project sceleton

MADDE-0.6.72 ~/madde
- $ mad pscreate -t qt_simple skeleton
Skeleton skeleton, type=qtprog created

//The code has been edited to read a .txt file.
//I created and included into the code the intended Debian folder //structure.

MADDE-0.6.72 ~/madde
- $ cd skeleton

MADDE-0.6.72 ~/madde/skeleton
- $ mad qmake

MADDE-0.6.72 ~/madde/skeleton
- $ mad make

MADDE-0.6.72 ~/madde/skeleton
- $ mad dpkg-buildpackage
>>


My goal is to create simple program to my N900 which reads and displays a simple "Hello world!" string from an external file (e.g. from a.txt). Please help! I read all the articles about Debian packaging, but no solution.

Thank you for your help!

Last edited by sakal; 2011-02-12 at 21:25.
 
Posts: 726 | Thanked: 345 times | Joined on Apr 2010 @ Sweden
#2
For anyone to help you, you need to describe HOW it fails to read the file.

Do you get an error? Some special return value?

How do you try to open the file?
 
Posts: 7 | Thanked: 0 times | Joined on Feb 2011
#3
There's no any error message. The program simply starts and right after stops without error messages. The program does not display just a black screen with the program's name in the title bar (this black screen is visible only for a moment, after this everything disapears).

I tried to open the program from the application manager (which is available by tapping its icon next to the time inscription and the battery life indicator)

Last edited by sakal; 2011-02-12 at 21:46.
 
Posts: 28 | Thanked: 13 times | Joined on Nov 2010 @ Tampere, Finland
#4
Since it is your program, you obviously need to program the error message in it yourself...

In your code, where you read the data file, check for existense of the file with QFile::exists() or by other means. After that check for succesfull opening and reading of the file. And in case of failure, pop up a message box that explains the error and waits for the user to tap it to close it.
 
Posts: 7 | Thanked: 0 times | Joined on Feb 2011
#5
Finally I could start my application on my N900 (removed a bug), but the "Hello world!" message does not display from the external .txt.
Maybe this happens because of the .txt is not included into the package or it is in the wrong path?!
My program displays the "Hello world!" message from the .txt if the program is running from Qt creator.
 
Posts: 1,086 | Thanked: 2,964 times | Joined on Jan 2010
#6
Originally Posted by sakal View Post
Finally I could start my application on my N900 (removed a bug), but the "Hello world!" message does not display from the external .txt.
Maybe this happens because of the .txt is not included into the package or it is in the wrong path?!
My program displays the "Hello world!" message from the .txt if the program is running from Qt creator.
Are you including the txt file in the qrc resources package? Are you creating a file if it's not found? It's difficult to second guess how you are handling this in your project, it would make it much easier for us to help you if you quoted some code and explained how you are trying to do this
__________________
Follow me on my neglected twitter @kojacker

Cybot950 - Control a robot with your N9/N950
SMSPetFeeder - Build a Bluetooth/SMS dog feeder with Qt, N950, and arduino
Nerf950 - Use your N9/N950 to fire a Nerf gun
 
Posts: 7 | Thanked: 0 times | Joined on Feb 2011
#7
I don't know what "qrc resource package" is. Could you please explain it?

Here is my code:
Code:
#include<QtCore>
#include<QLabel>
#include<QFile>
#include<QtGui>
#include<QString>
#include <iostream>
#include <QMessagebox>


class DblVec : public QVector<int>{
public:
     DblVec(int n):QVector<int>(n){}
};
using namespace std;

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    QWidget *window         = new QWidget;
    QGridLayout *layout     = new QGridLayout;
    QPushButton *readFile   = new QPushButton;
    QString                 date;
    quint32                 size;
    DblVec                  line(size);
    QTextBrowser *browse    = new QTextBrowser;
    QScrollBar *scrollbar   = new QScrollBar;
    QFile infile("opt/Mad Qt example/data.txt");

    window->setWindowTitle("Data");
    readFile->setText("Button");
    layout->addWidget(readFile, 0, 1);

    if ( infile.open(QIODevice::ReadOnly |QIODevice::Text) )
    {   QString line2;
        QTextStream stream( &infile );
           while(!stream.atEnd())
        {
              line2 = stream.readAll();
        }

           browse->setText(line2);
            browse->setVerticalScrollBar(scrollbar);
            browse->show();
            infile.close();
     }

    layout->addWidget(browse, 0, 0);
    window->setLayout(layout);
    window->resize(500, 400);
    window->show();
    return a.exec();
}

And here is my directory structure for the packaging process:


Last edited by sakal; 2011-02-16 at 19:52.
 
Posts: 7 | Thanked: 0 times | Joined on Feb 2011
#8
Furthermore appreciated any help which describes how to create an application for the N900 which reads information from an external data file.

Last edited by sakal; 2011-02-13 at 21:14.
 
Posts: 726 | Thanked: 345 times | Joined on Apr 2010 @ Sweden
#9
If you want to protect formatting of code, you use the code tag around it, like so:
Code:
foo();
  bar();
     fie();
Regarding debugging your program:
You have a while-loop where you read all the data into one QString. You could always try to output this string to the console.

The file you are trying to read from is indicated by a relative path. For this to work, your program must be placed, and run, from this relative root, containing the "opt" directory.

I'd suggest you try to use an absolute path, like "/opt/<whatever>", and see where that takes you. Also, add an else branch to get output to the console if the infile.open call fails.
 
Posts: 7 | Thanked: 0 times | Joined on Feb 2011
#10
My problem has been solved. Now I am able to create external file using applications for my n900.

If you want to create an app for your n900 which reads and displays data from an external file here are the steps what makes you happy:

1. Download and install Qt creator.

2. Set up the qmake and necessary folders in the options.

3. Download and install MADDE Developer.

4. Create the Project and package skeleton with MADDE using the following command:
Code:
mad pscreate -t qt_simple yourproject
5. Edit the automatically created source code in the src folder. (In this case we are using a code that reads info from an external file e.g. data.txt) Save all.

6. Open the .pro file and add the following lines to it:
Code:
INSTALLS    += data
data.path  = /opt/txt
data.files  = data.txt
The data.path is the folder structure you will put into your package. (So you have to implement into your code the following path for the .txt: "/opt/txt/data.txt" )
Data.files is the path where your data.txt exists. Now this is near your .pro file. (The .txt and the .pro is in the same folder.)

7. Open MADDE and navigate to the folder where the .pro file exists and enter the following commands:
Code:
mad qmake
mad make
mad dpkg-buildpackage
8. Your package is now ready to copy to the N900 and install.

Enjoy!



Thank you for your help!

Last edited by sakal; 2011-02-20 at 14:12.
 
Reply


 
Forum Jump


All times are GMT. The time now is 06:59.