Results 1 to 12 of 12

Thread: GUI Development Help

  1. #1
    Join Date
    Jun 2011
    Posts
    203
    Thanks
    7
    Thanked 4 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default GUI Development Help

    Hi, I'm creating a GUI and I would love some guidance as programming isn't my strongest point.

    I would inevitably like my GUI to work on Windows, Linux and Mac OS (this is why I decided to use QT as the way I understand it, it enables me to do this very thing).

    As for the questions in regards to my GUI.

    I started out by creating a new Qt Widget Project and selected Qt Gui Application.

    I then went into the visual design page where I put together my GUI visually. However, I don't quite know which components to use for my intended purpose.

    I'm basically trying to create this:

    http://wallentins.com/images/CSL/FRO...proach%201.jpg

    So this widget will have a screen, it will have page select keys (e.g. DIR, PROG, PERF), it will have "line select keys" - that's those buttons next to the screen with -, a keyboard and a numberpad and finally keys enabling me to scroll through pages shown in the display of the corresponding Page (e.g. DIR, PROG etc).

    The tricky part with all of this is that essentially, the "Page" keys select different pages, the keyboard and number pad enable the user to input data into the screen and the line select keys then copy the input data and paste them into the corresponding "lines" adjacent to the pressed line select key.

    My problem is that I don't know which objects to use to create the layout for my GUI. I can create all the buttons of an appropriate size but then I don't know how I would link their as I explained, quite unique functionality to the screen part. Speaking of which, what would I use as the screen?

    I was thinking of using something along the lines of the tab widget for the pages and then have a stacked widget assigned to each tab of the tab widget and then maybe use concealed radio buttons as the "action" which selects the required field to be used for data storage but I don't know whether this would work.

    If I simply insert all the buttons that I require, then I can create the exact layout I need, however I don't what to use for the screen... if I use the second idea that I presented i.e. tab widget + stacked widget etc, then I don't know how to modify those widgets to the layout that I desire.

    Any ideas on how I would tackle this problem?

  2. #2
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,042
    Thanks
    8
    Thanked 133 Times in 128 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: GUI Development Help

    You have to start with the Qt Tutorial found inside Qt Assistant before going into such a complex code.

  3. #3
    Join Date
    Jun 2011
    Posts
    203
    Thanks
    7
    Thanked 4 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: GUI Development Help

    Hi, thanks, I just tried the "Creating Qt C++ Application" tutorial with the textFinder example and I more or less understood what was happening, however I'm not quite sure what Qt Assistant is. A search suggests that it should be in the Qt installation folder (On Windows, Qt Assistant is available as a menu option on the Qt menu.) but I don't see it there and a search of the whole computer has also come up with no results. Any ideas?

  4. #4
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,042
    Thanks
    8
    Thanked 133 Times in 128 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: GUI Development Help

    Qt assistant is just a app which shows html help of qt with some support for searching and indexing. If you have QtCreator then its already integrated in it. Or you can just jump to the online help at qt.nokia.com . Anyways, after u have read the tuturial, can you make a simple Calculator application without looking at the tutorial? If you can then only proceed with your original application.

  5. #5
    Join Date
    Jun 2011
    Posts
    203
    Thanks
    7
    Thanked 4 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: GUI Development Help

    Awesome thanks. Another question though... what's wrong with just doing this whole project in Qt Designer and using Edit/Signals Slots? Or is this going to be a very inefficient process?

    And a somewhat stupid question... when I add an object in Qt Designer, why does it not show the code for it in any of the .cpp files in the project viewer list? Only shows new objects/widgets getting created in xml view?
    Last edited by Atomic_Sheep; 22nd June 2011 at 17:05.

  6. #6
    Join Date
    Jun 2011
    Posts
    203
    Thanks
    7
    Thanked 4 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: GUI Development Help

    Hi, well I've been trying to create a calculator (haven't found any tutorials and not looking for one), have been trying to figure it out just by learning C++ theory. However I'm stuck...

    I created a GUI... I made a button for each of the digits, and a button for each of the basic operators i.e. + - x /

    After this, I added slots to all the buttons (Clicked()).

    For the display I added the lcdNumber widget.

    I'm not sure whether there is an easier way of doing it, but I created a class called values (2 files .h and .cpp). For the moment, I'm not sure how to simply attach a number to the back of another one, I'm guessing use string and then convert to integers in the function which gets called when the = key is pressed. Anyway, this class will house all the numbers needed e.g.

    currentnumber - the number which is currently being created
    firstnumber - after you press an operator key, the currentnumber which was being created gets assigned to firstnumber
    secondnumber - after you press the equals key, the currentnumber gets assigned to secondnumber

    I'll also need to add members to remember which operator was pressed

    e.g. operator which will get a value of 1 2 3 4 depending on which operator gets called

    so in the slot for the quals key:

    void Calculator:n_pushButton_15_clicked() //this is the slot which gets called when the equals sign gets called
    {

    }

    I'll be able to write code with a bunch of if statements, which will calculate

    answer = firstvalue operator secondvalue

    Somehow...

    Q1.) How is my solution looking so far?

    Q2.) I have no idea how to get the values to be shown in the lcdNumber widget? I'm not sure whether with the code that I've proposed, I'll need to create a connection or whether I'll be able to just add code for each button press slot which will directly affect the output of the lcdNumber widget. The latter is the way that I intended to do it but I'm unable to figure out how to get it to work. I'm not good enough at C++ to know enough functions and objects etc to know how to do this.

  7. #7
    Join Date
    Oct 2010
    Location
    Berlin, Germany
    Posts
    358
    Thanks
    18
    Thanked 68 Times in 66 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: GUI Development Help

    Quote Originally Posted by Atomic_Sheep View Post
    I'm not good enough at C++ to know enough functions and objects etc to know how to do this.
    then you should read some tutorials about plain c++ before starting with Qt...

  8. #8
    Join Date
    Jun 2011
    Posts
    203
    Thanks
    7
    Thanked 4 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: GUI Development Help

    I know how to do cin and cout and generic stuff which is taught in all tutorials but stuff to do with more graphical user interfaces I don't have any experience with and most tutorials just concentrate on the common themes presented in all C++ tutorials which I've read and watched plenty of. That's more what I was getting at.

    EDIT: Can someone please explain what this code means?

    #include <qlcdnumber.h>
    #include <qslider.h>

    #include "mywidget.h"

    MyWidget::MyWidget( QWidget *parent, char *name ) : QVBox( parent, name )
    {
    QLCDNumber *lcd = new QLCDNumber( this );
    QSlider *s = new QSlider( QSlider::Horizontal, this );

    connect( s, SIGNAL(valueChanged(int)), lcd, SLOT(display(int)) );
    }

    All I know that it's a constuctor...
    Last edited by Atomic_Sheep; 27th June 2011 at 11:32.

  9. #9
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: GUI Development Help

    Which part are you struggling to understand?

    Its a constructor as you say, and its using an initialiser list to call the inherited class QVBox constructor with the arguments parent & name.

    Do you understand initialiser lists and inheritance ?

  10. #10
    Join Date
    Jun 2011
    Posts
    203
    Thanks
    7
    Thanked 4 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: GUI Development Help

    Started reading inheritance as you suggested, however, what I don't understand are the nuances of copy and direct initialization. I'm very familiar with copy initialization but why have direct and why have 2 different types? Is it even possible to do:

    int a(7); ?
    and is that the same as :
    int a = 7;?

    EDIT: I think I get where my confusion lies apart form not understanding other aspects of the afore mentioned code (so reading about those aspects right now)...

    The thing that I don't understand is the coexistence of default and constructors which have parameters. I think this is an example of a constructor which has been called with specific values assigned to members...

    I just need to practice compiling a bunch of classes in different scenarios and have a look at the results and convince myself that they are necessary. I just don't quite understand why we can't simply initialise the values of class members when we are actually writing code in the main.cpp section and are creating a variable of that class? I know we can have that but I don't understand why usually a default or a(more than one) parametrized constructor is included if we can always assign values later anyway or is this another fail safe mechanism used to simplify debugging?
    Last edited by Atomic_Sheep; 28th June 2011 at 00:27.

  11. #11
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,042
    Thanks
    8
    Thanked 133 Times in 128 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: GUI Development Help

    Quote Originally Posted by Atomic_Sheep View Post
    I don't understand why usually a default or a(more than one) parametrized constructor is included if we can always assign values later anyway or is this another fail safe mechanism used to simplify debugging?
    Simple Answer:- To reduce your typing.
    for example:-
    Qt Code:
    1. class MyClass
    2. {
    3. private:
    4. int val;
    5. public:
    6. MyClass() { /*empty*/ }
    7. MyClass( int newVal ) { setVal(newVal); }
    8. void setVal(int newVal) { val = newVal; }
    9. int getVal() { return val; }
    10. }
    11.  
    12. int main()
    13. {
    14. MyClass obj1;
    15. obj1.setVal(5);
    16.  
    17. MyClass obj2(5);
    18.  
    19. }
    To copy to clipboard, switch view to plain text mode 

    as you see initializing obj1 requires two lines of code where as obj2 only requires 1 line. Consider the case where you have to create 50 objects. So you would be writing a lot of code and lot of bugs.

    Complicated Answer:- It reduces code duplication, The object is assumed to be usable after its creation. You dont have to document the class like "Make sure u call setVal() at least once before calling getVal() otherwise the returned value is garbage.". And many others benefits.

  12. #12
    Join Date
    Jun 2011
    Posts
    203
    Thanks
    7
    Thanked 4 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: GUI Development Help

    Ok thanks, I had a feeling it was more of an implementation thing. Back to reading, I think I'm coming close to understanding.

Similar Threads

  1. Re: [ANN] Voip Development Kit (VDK) 2.0
    By alienpenguin in forum Qt-based Software
    Replies: 2
    Last Post: 9th December 2011, 05:56
  2. Game Development
    By AlexanderPopov in forum General Discussion
    Replies: 6
    Last Post: 15th October 2011, 01:55
  3. Embedded Qt development on a Mac
    By charleskemp in forum Qt for Embedded and Mobile
    Replies: 0
    Last Post: 30th June 2010, 19:47
  4. Replies: 1
    Last Post: 13th August 2009, 17:32

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.