Author Topic: My first application: Done. A few questions  (Read 5281 times)

jdf

  • Newbie
  • *
  • Posts: 33
    • View Profile
    • http://
My first application: Done. A few questions
« on: March 13, 2004, 09:45:11 pm »
I am new to Qt and C++ and only progran as a hobby.   I got my Z one month ago.  I just finished my first application thankx to some help from members of this board.

The app is just a Unit Conversion Program.  Wrote it as a training exercise, not because anyone needed another conversion program!   In any case I attached the source code to this message.  (don\'t expect it to be pretty).  I tested the file and it will compile and run under dev-x86-qpe environment, dev-arm-qpe and transferred to Z works fine; also under winXP envronment works fine.    The program uses customizable text files as the conversion database.  I included these data files in the attachment too.  They should be in the same directory where you run the program from.

Here are my questions:

1) What is the best way to get the application to start full screen.  What screen size should be used?   My app seems to start a little bit less than full size and then I can maximize it.

2) I use a QLabel and a QLineedit.  How can I set the color for those backgrounds?

3) The Lineedit accepts keyboard entry from the Sharp hardware.  I tried to do a connect of the textChanged signal to a Slot in mysoftware but this never works.  Maybe some one could look at that connect statement.

4) I used a setCaption, but the title doesn\'t appear in the title bar?

Sorry if some of these questions may be obvious, but I have spent hours searching and trying to resolve them.

I placed the files here too:
                                             http://www.delferro.net/zaurus

Thankx\'JDF
JDF
SL-5500; CF MODEM; CF Wireless; CF & SD Storage;
Fedora CORE 1; WinXP

lpotter

  • Sr. Member
  • ****
  • Posts: 450
    • View Profile
    • http://qtopia.net
My first application: Done. A few questions
« Reply #1 on: March 14, 2004, 12:37:15 am »
JDF,
It\'s best to use dynamic layouts, that way your applications can resize itself according to the screensize, so it will work on 5500\'s, and c760\'s, and even screens that are 176x220 (like on a phone). I find gridlayouts are the easiest to code by hand..
You should use QPEApplication, instead of QApplication if you want to use Qtopia/Opie:

1)
#include <qpe/qpeapplication.h>

QApplication jdfapp( argc, argv );
j_uconvert jmain;
jdfapp.showMainWidget( &jmain );

2) Why do you want to color those? It\'s probably best not too, for the sake of gui uniformity.
3)
textChanged is called every keystroke, so you might want to use something else, like returnPressed, and then get the text of the QLineEdit
with in your slot
QString lineEditString = j_le_basevalue->text();
Software Engineer, Systems Group, MES, Trolltech
irc.freenode.net #qtopia
http://qtopia.net

jdf

  • Newbie
  • *
  • Posts: 33
    • View Profile
    • http://
My first application: Done. A few questions
« Reply #2 on: March 14, 2004, 11:57:57 am »
lpotter,
Thankyou for helping me out.  Here is some additional info
0. screen size:
I think I am using an QVbox for the layout.  But it still seems not to start out MAXIMIZED,  I also tried a grid layout in place of the QHBox and that also didn\'t start out MAXIMIZED.  It starts a little smaller than screen and then I can tap the MAXIMIZE button on title bar and it maximizes to the screen.    How can I start out maximized to the device?

1) I made the changes you pointed out
     #include <qpe/qpeapplication.h>
     QApplication jdfapp( argc, argv );
      j_uconvert jmain;
      jdfapp.showMainWidget( &jmain );
But then I get a problem with the later statements in main as I had them, including
      jmain->show();  
        error: (base operand of `->\' has non-pointer type `j_uconvert\'
SO, I left everything as I originally had it But I did add my missing
     #include <qpe/qpeapplication.h>
      and deleted     #include <qapplication.h>
NET RESULT:  seems to perform same as original as far as the screen size problem.

2) Why do you want to color those?
Well the Linedit comes up the default WHITE which is OK.  I want the LABEL below it to be White and kind of similar to the lineedit.  The label comes up the same as the background screen.  I would like it to be White or red say.  I guess I could use a Linedit instead and make it noneditable.

3) textChanged is called every keystroke,

That\'s exactly what I want for this application,  For each keystroke made I want to read the current value of the box.   I thought my signal slot was configured right, but it never makes it to the slot.

4) SetCaption still doesn\'t appear even though changed to
 #include <qpe/qpeapplication.h>

Again,  I really appreciate your feedback.  It has been difficult learning cpp, oop, QT, but this forum is great!!

JDF
JDF
SL-5500; CF MODEM; CF Wireless; CF & SD Storage;
Fedora CORE 1; WinXP

markb

  • Jr. Member
  • **
  • Posts: 54
    • View Profile
    • http://
My first application: Done. A few questions
« Reply #3 on: March 14, 2004, 07:23:37 pm »
Hi jdf,

I haven\'t had a chance to look at your latest code yet.
But I can help out with one thing I spotted from your last post:

Quote
j_uconvert jmain;
jdfapp.showMainWidget( &jmain );
But then I get a problem with the later statements in main as I had them, including
jmain-]show();
error: (base operand of `-]\' has non-pointer type `j_uconvert\'

That looks like a slight pointer problem.
If you have an object, you call a method on it using \".\".
But If you have a pointer to an object, you call a method using \"-]\".

e.g.

Code: [Select]
MyClass anObj;

anObj.callMethod( arg1, arg2 );



MyClass *objPtr = new MyClass();

objPtr->callMethod( arg1, arg2 );


So, when you had a problem with
Code: [Select]
jmain->show()
it\'s because jmain isn\'t a pointer to an object, so you should do this instead:
Code: [Select]
jmain.show()

You\'ve probably spotted that yourself by now.
But I thought I\'d mention it anyway.

- Mark

BlackCardinal

  • Jr. Member
  • **
  • Posts: 70
    • View Profile
    • http://www.gelhaus.net
My first application: Done. A few questions
« Reply #4 on: March 14, 2004, 08:22:11 pm »
I\'m going to jump in here... in lpotter\'s post there is a typo.  The code for the application object should actually be:

#include <qpe/qpeapplication.h>

QPEApplication jdfapp( argc, argv );
j_uconvert jmain;
jdfapp.showMainWidget( &jmain );

The typo was still declaring jdfapp to be a QApplication instead of a QPEApplication.  I think if you use QPEApplication the window will automatically run maximized, and this will solve your mysterious pointer error, too.

Black Cardinal
BlackCardinal : http://www.gelhaus.net : Zaurus page

SL-C1000, Cacko ROM v1.23
Lexar SD 512MB, Kingston CF 512MB
Symbol Spectrum24 CF 802.11b

SL-5500 Sharp ROM v3.10
Lexar SD 256MB
Pocketop keyboard, Nutshell 207 leather case

BlackCardinal

  • Jr. Member
  • **
  • Posts: 70
    • View Profile
    • http://www.gelhaus.net
My first application: Done. A few questions
« Reply #5 on: March 14, 2004, 08:40:14 pm »
OK, this time I actually downloaded your code and built it.  Changing to QPEApplication does fix the screen maximizing problem.

setCaption() isn\'t working because it\'s not being called on the parent widget (j_uconvert), but instead on a QVBox contained within the parent widget.  Change the call to simply:

setCaption(\"UCzz\");

The connect call isn\'t working for two reasons:

1)  It should be a call to the static QObject::connect function, which needs to be made explicitly, and
2)  There are some extra pipe symbols in the line.

Here is how this statement should be made:

QObject::connect( j_le_basevalue, SIGNAL(textChanged(const QString&)), this, SLOT(sl_RealKYBD(const QString&)) );

Nice little program, by the way!  Looks like you\'re having fun!  
BlackCardinal : http://www.gelhaus.net : Zaurus page

SL-C1000, Cacko ROM v1.23
Lexar SD 512MB, Kingston CF 512MB
Symbol Spectrum24 CF 802.11b

SL-5500 Sharp ROM v3.10
Lexar SD 256MB
Pocketop keyboard, Nutshell 207 leather case

jdf

  • Newbie
  • *
  • Posts: 33
    • View Profile
    • http://
My first application: Done. A few questions
« Reply #6 on: March 14, 2004, 11:59:40 pm »
OK Blackbird.....
Seems like you zeroed right in on it!!  Thankx!

I made only the changes you suggested in your post.
-Caption is correct
-Keyboard works great now
-Not sure about the full screen yet, but I think it will work.

In my qvbf it seems like it wasn\'t full screen and I could move the window around.  Also when I ran it from terminal on Z5500 it didn\'t go full screen either and I could move the window around, but caption and keyboard were fine on the Z.

Let me try some other things and verify, before I ask it again!

I thought maybe if i packaged it onto the Z it would work, so I made an ipk, but have been unsuccessful at getting the Z to recognize the ipk for install.  The only other ipk I made was for the \"example\" program and I did that OK, so I thought I did this one exactly the same.

If someone could look at the IPK, i\'d appreciate it! :wink:  

I put the ipk and current source here:
http://www.delferro.net/zaurus

Thankx everyone.  Oh, markb, thankx for the insight into the pointer to an object and the actual object stuff.  It helped me understand some other things!!

JDF
JDF
SL-5500; CF MODEM; CF Wireless; CF & SD Storage;
Fedora CORE 1; WinXP

BlackCardinal

  • Jr. Member
  • **
  • Posts: 70
    • View Profile
    • http://www.gelhaus.net
My first application: Done. A few questions
« Reply #7 on: March 15, 2004, 03:48:48 pm »
The data.tar.gz file in the IPK includes a zero-length file \"Packages\" that it\'s trying to install to /, which is a read-only directory if you install to memory.  Remove that file and it will install fine.
BlackCardinal : http://www.gelhaus.net : Zaurus page

SL-C1000, Cacko ROM v1.23
Lexar SD 512MB, Kingston CF 512MB
Symbol Spectrum24 CF 802.11b

SL-5500 Sharp ROM v3.10
Lexar SD 256MB
Pocketop keyboard, Nutshell 207 leather case

jdf

  • Newbie
  • *
  • Posts: 33
    • View Profile
    • http://
My first application: Done. A few questions
« Reply #8 on: March 15, 2004, 11:13:56 pm »
I apologize for my last post referencing \"Blackbird\" :!:
BlackCardinal:  Thankx again.  I am getting the hang of this now!  

OK: The program is basically working the way I wanted thanks to your suggestins.  I have an ipk that successfully installs itself with icon, help file, and the data files into home/zaurus.  It then executes from its icon in the Applications TAB.   Does its stuff and exits cleanly.  I am pretty happy.

My last issue is the screen layout.  I have code in the ( j_uconvrt.cpp ) constructor to make a Gridlayout with a 5 row 2 column box.  The first row is the file, the second row is the category, on the third row I have the Lineedit and the baseunit combo box side by side in col 1 and col 2. and 4th row has the output text and the converted unit combo box side by side.

In any case the layout doesn\'t seem to be applied. No errors, but i just get a single column VBox layout.

If anyone wants to try out the ipk or look at the code it can be downloaded here   http://www.delferro.net/zaurus
JDF
SL-5500; CF MODEM; CF Wireless; CF & SD Storage;
Fedora CORE 1; WinXP

BlackCardinal

  • Jr. Member
  • **
  • Posts: 70
    • View Profile
    • http://www.gelhaus.net
My first application: Done. A few questions
« Reply #9 on: March 16, 2004, 03:44:18 pm »
Quote
I apologize for my last post referencing \"Blackbird\"
Hey, no problem!  

I think it\'s because the main window is derived from QVBox, instead of QWidget.  Try deriving your class j_uconvert from QWidget, and create a master layout that\'s a QVBoxLayout.  Then insert your grid layout into this master layout.

Or, if your grid layout is the top level layout, you can insert it directly into j_uconvert, without needing the QVBoxLayout.

Kind of like this:

Code: [Select]
class j_uconvert : public QWidget
Code: [Select]
j_uconvert::j_uconvert(...) : QWidget(...)

{

     QVBoxLayout *master = new QVBoxLayout(this);



     QGridLayout *grid = new QGridLayout(this);

     master->addLayout(grid);



     QSomeWidget *otherWidget = new QSomeWidget(this, ...);



     grid->addWidget(...);

     grid->addWidget(...);



     master->addWidget(otherWidget);



     master->activate();

}


or:

Code: [Select]
j_uconvert::j_uconvert(...) : QWidget(...)

{

     QGridLayout *grid = new QGridLayout(this);



     grid->addWidget(...);

     grid->addWidget(...);



     grid->activate();

}
BlackCardinal : http://www.gelhaus.net : Zaurus page

SL-C1000, Cacko ROM v1.23
Lexar SD 512MB, Kingston CF 512MB
Symbol Spectrum24 CF 802.11b

SL-5500 Sharp ROM v3.10
Lexar SD 256MB
Pocketop keyboard, Nutshell 207 leather case

jdf

  • Newbie
  • *
  • Posts: 33
    • View Profile
    • http://
My first application: Done. A few questions
« Reply #10 on: March 16, 2004, 10:16:55 pm »
Blackbird, thankx again....maybe I\'ll call this program ucbb !

I have the gridlayout working.  Ran into a few glitches trying to set min row height and columns to control the layout  Qt uses newer methods that didn\'t work on QPE
                     
current Qt method is setRowSpacing
for QPE use legacy methods: addRowSpacing

It basically installs and looks great; however, the screen will expand larger than the screen size and start hiding widgets.   This happens when the Lineedit gets a very large number in it!    Before the gridlayout, this didn\'t happen.  hmmmmmm.   I\'ll try a few different ways of implementing the widgets and see if that changes anything.  right now I just implement it in the main widget.  Maybe if I implement it inside the QVBox.  I\'ll experiment!

I put both the ipk and the current files at http://www.delferro.net/zaurus

In any case, I have progressed to where I feel comfortable and can take a break and CLEAN THE HOUSE AND GARAGE AND RUN ALL THOSE PROMISED ERRANDS before my wife gets back from her vacation!!   That\'s the only reason I got to play with this thing for the last 3 weeks!

I\'ll get back to this next week.  I really appreciate all the help directly from blackbird and markb, as well as all the other informative posts all over this board!

jdf
JDF
SL-5500; CF MODEM; CF Wireless; CF & SD Storage;
Fedora CORE 1; WinXP