Author Topic: C++ newbie  (Read 4589 times)

JeffElkins

  • Newbie
  • *
  • Posts: 8
    • View Profile
    • http://
C++ newbie
« on: December 08, 2003, 09:12:00 am »
I\'m trying to move into c++ for the Zaurus and am at the baby step stages.

I\'ve had some luck with apps that have only one screen and am now trying to develop one that displays two. With the code below, I can display either ScreenOne or ScreenTwo by commenting out one or the other. My goal is to  have the button on screen 1 call screen 2 and vice-versa.

My coding background is limited to procedural languages. I\'m working with the \'Thinking in C++\' books,  but this my first exposure to OOP.

Can someone help a newbie?

Thanks

Jeff Elkins


int main( int argc, char **argv )
{
    QPEApplication a( argc, argv );

    ScreenOne w;

    w.setCaption(\"Gather Input\");
    w.setGeometry( 0, 15, 240, 320 );
    a.setMainWidget( &w );
    w.show();
    return a.exec();

    ScreenTwo z;

    z.setCaption(\"Display Calculations\");
    z.setGeometry( 0, 15, 240, 320 );
    a.setMainWidget( &z );
    z.show();
    return a.exec();

}

TimW

  • Sr. Member
  • ****
  • Posts: 296
    • View Profile
C++ newbie
« Reply #1 on: December 08, 2003, 09:22:21 am »
You should probably only have one main widget but that widget could hold a \"QWidgetStack\". Quoting from the QT docs:

\"The QWidgetStack class provides a stack of widgets, where the user can see only the top widget.
The application programmer can move any widget to the top of the stack at any time using the slot raiseWidget(), and add or remove widgets using addWidget() and removeWidget().\"

My \"mainWidget\" has the following code in the constructor:

    editorStack = new QWidgetStack( this );
    setCentralWidget( editorStack );
    m_annoWin = new CAnnoEdit(editorStack);
    editorStack-]addWidget(m_annoWin, get_unique_id());
    m_infoWin = new infowin(editorStack);
    editorStack-]addWidget(m_infoWin, get_unique_id());

CAnnoEdit and infowin are ordinary widgets and editorstack is a pointer to a QWidgetStack which is a member of my main window. I just use (eg)

   editorStack-]raiseWidget( m_infoWin );

to swap between widgets (IIRC I have about 5 widgets in my stack so it should easily cope with your initial two).

tumnus

  • Hero Member
  • *****
  • Posts: 1176
    • View Profile
    • http://www.cpinkney.org.uk
C++ newbie
« Reply #2 on: December 08, 2003, 09:42:17 am »
You also need to remove that first instance of \"return a.exec();\" as that is exiting the programme after showing the first widget. That\'s why you can only show the second one by commenting out the first block.

But as TimW said, you probably want to use the QWidgetStack.
# Search the Zaurus Howtos ## Search the Zaurus FAQs ## Find Z software at ELSI #
--------------------
UK SL5500 with Sharp ROM 3.13, SL5600 with Sharp ROM 1.32 - SuSE 9.0 Pro, Windows XP Home
Qualendar for Calendar and Todo
Socket Bluetooth CF Card (Rev F), Kingmax 512MB MMC Card, Palm Tungsten T Stylus,
Pretec CF->Smartmedia Adapter, Semsons Universal Battery Extender

JeffElkins

  • Newbie
  • *
  • Posts: 8
    • View Profile
    • http://
C++ newbie
« Reply #3 on: December 08, 2003, 05:58:04 pm »
Thanks.

Can you recommend some example QWidgetStack code...something that compiles, that I could modify and learn from, but goes beyond \'hello world\'?

Jeff

TimW

  • Sr. Member
  • ****
  • Posts: 296
    • View Profile
C++ newbie
« Reply #4 on: December 09, 2003, 05:24:29 am »
IIRC the editor app example (might be called textedit?) which comes with the Qtopia SDK is a good example. There is one screen which is a file selector and another which is the actual editor. Neither screen is particularly complex so that reduces the scope for confusion...plus it is where I got my start on widget stacks 8^).

Anonymous

  • Guest
C++ newbie
« Reply #5 on: December 09, 2003, 09:42:28 am »
Thanks Tim!