Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Adding a GUI to a C++ program

Options
  • 15-10-2009 1:15pm
    #1
    Registered Users Posts: 1,586 ✭✭✭


    Hi all,

    Major noob question ... I have practically zero programming expierience and have recently started to learn C++ , its going well but every program I write is command line based. I had a quick look at the end of the book and it seems it never moves on to making your programs GUI windows friendly.

    Is this something that can be done easily or do i have to learn a whole other language ?

    thanks !


Comments

  • Closed Accounts Posts: 1,567 ✭✭✭Martyr


    you could try QT or wxWidgets (both cross-platform)

    check youtube for tutorials on how to use these.


  • Closed Accounts Posts: 5,082 ✭✭✭Pygmalion


    Gaz wrote: »
    Major noob question ... I have practically zero programming expierience and have recently started to learn C++ , its going well but every program I write is command line based. I had a quick look at the end of the book and it seems it never moves on to making your programs GUI windows friendly.
    The language itself has no way of creating graphical components (pretty much no languages do, and the ones that do are usually really crap*, it's not a downside of the language), that stuff is generally handled by the OS/Window Manager/3rd party libraries.
    As such there are numerous ways to do it, some easier than others, some more suitable for certain tasks than others (SDL is great for 2D games, animations and the like but terrible for simple programs, vice-versa for stuff like GTK or Qt) and some will only work on certain Operating systems.

    A fairly large list is at http://en.wikipedia.org/wiki/List_of_widget_toolkits.
    The most commonly used would be The Windows API for Windows and Cocoa for Mac.
    wxWidgets, GTK and Qt will work on all major Operating systems.

    In my opinion the best to learn would be Qt, it's specifically designed for C++ (but it's very commonly used in languages such as Python), easy to use (though your first few GUI programs will be difficult regardless what you choose.). In addition to just graphics it has libraries for Networking, XML parsing, multimedia (audio and video) and a HTML rendering engine, which can make it insanely useful in that you can incorporate all these things into a program without having to use yet another library, and with much less effort. It's developed by Nokia now so has very active, well-funded development.
    I've never used GTK, and I only used wxWidgets a few years ago, back then it seemed very buggy, but I'd say by now it's quite good.

    *Though Java does seem to do it well and is a fairly well liked language.
    Is this something that can be done easily or do i have to learn a whole other language ?
    It's not much harder in C++ than any other language, and since many of the toolkits were written in C or C++ it can be a lot easier to understand them and to get help with them if using these languages.


  • Closed Accounts Posts: 845 ✭✭✭yupyup7up


    Why not use MFC? its Doc View architecture based, and allows you to create windows style programs via C++ using .NET


  • Registered Users Posts: 981 ✭✭✭fasty


    Do not use MFC! For starters, using it required more knowledge of the Windows API than you'd think to get decent results and furthermore, while it is C++ based, a lot of the functionality is hidden behind macros which could confuse someone new to the language.

    And it's got nothing to do with .Net trust me, I've had to mix .Net and MFC code and the bitter taste is still in my mouth!


  • Registered Users Posts: 9,579 ✭✭✭Webmonkey


    QT is excellent and easy to learn plus it adds a lot more useful things like cross platform networking/threading etc.


  • Advertisement
  • Registered Users Posts: 1,228 ✭✭✭carveone


    You don't say if you are programming under Windows or Unix. And yes, lots of books seem to avoid the whole GUI aspect. These days I guess you are supposed to Webify it and opt out of creating a gui app :rolleyes:

    I'll get some hassle for this but for Windows, you might want to try raw Win32 first. I know, I know but if someone recommended MFC, I can recommend Win32! The thing is, it isn't that hard really and will give you a good basis for learning other frameworks. If you aren't au fait with Win32, asking questions about MFC can be fraught with difficulty (ie: people will assume that you get Win32 and will answer you as if you did).

    Nothing to stop you starting with this:
    #include <windows.h>
    
    int main()
    {
        MessageBox(NULL, "Hello World", "A Message" , MB_OK);
        return 0;
    }
    

    Well. It's GUI! I used TheForger's tutorial at http://www.winprog.org/tutorial/ to understand Win32 API. Other APIs are similar...

    Alternatively, use C# or VB.net ?


  • Hosted Moderators Posts: 7,486 ✭✭✭Red Alert


    If you're on a Mac you could try Cocoa/Objective-C but probably QT is your best bet. The dev tools (QTCreator) are free to download and include all the bits you need. Also, the applications you make will work on Mac, UNIX and Windows.


  • Registered Users Posts: 1,421 ✭✭✭Steveire


    It's Qt, not QT.


  • Registered Users Posts: 9,579 ✭✭✭Webmonkey


    True, the Q because it looked nice in that font and the t for toolkit.


Advertisement