I have to create an app that at the very basic level does this: reads some integers from a file.If it reads 5,then it creates a window with 5 buttons,or 5 lists,or checkboxes.
What library should I use for something like this?
Jump to content
Posted 22 July 2013 - 07:56 PM
Qt can do that easily, for Mac, Linux, or Windows. Many libraries can.
By 'app', do you mean a smartphone application or a desktop application?
Posted 22 July 2013 - 08:46 PM
If you want to do it using just the Win32 API, (and want a dialog box with a variable number of controls) you can check out DLGTEMPLATEEX and all the associated nastiness. Here's an article about creating a simple input box:
... but I'd recommend googling as many examples as you can first before diving in.
If you don't want a dialog box you can just create control windows directly inside your main window, although controls look best in a dialog box really.
You're probably better learning a platform-neutral library like Qt if you want to do serious work involving dynamically created controls (or use C#, which makes GUI work really easy).
Posted 22 July 2013 - 09:08 PM
Qt is well-designed, well-documented, and cross-platform. It's been around for ages, and still under active development. Many Linux windowing systems are built ontop of Qt. It's very stable.
It's very nicely licensed, even for commercial projects. (LGPL = You can use it commercially, as long as you dynamically link to the DLLs instead of statically link).
On the flipside, it is HUGE. It has classes and functions for loads of stuff that you'll only need tiny pieces of every now and then, so it can seem quite overwhelming.
It also forces you to do things Qt's way, which can occasionally get annoying.
Further, it uses a signal-and-slot paradigm that, while very useful once you learn it, might throw you for a loop.
Qt even has it's own IDE, called QtCreator. It's really one of the best IDEs around for C++, even when not using Qt.
However, Qt is kind of finicky if not using QtCreator.
So, Qt is a big learning investment, but is not complex to learn. For a single small project, it's not worth the learning-investment. But if you're going to be making alot of desktop applications over the next few years, or if your project is a very big project, it's definitely worth it.
You can fully customize the appearance of your widgets, create your own widgets, or use any of the built-in widgets. It has a huge and active community, excellent documentation, and is extremely flexible. QtCreator has a built-in WYSIWYG drag-and-drop GUI builder (called QtDesigner) that's very nice to use, but you can also write your own code for classes (and you often use a mix of both anyway).
You can easily and rapidly assemble the visual interface of your project, so you can focus on the custom code that your project requires.
On the otherhand, if not careful, projects can rapidly become messy unless you actively make it a priority to keep your code clean.
I use Qt, and I love it alot, but it has its irritations as well.
It's so huge, I like to think of it as a collection of libraries (it's broken into about a dozen modules, but it could easily be subdivided further, it's so huge). It's similar to Boost in that manner: A huge collection of flexible and re-usable code sharing a common coding style and consistent interfaces, that encompasses many different purposes and features.
Edited by Servant of the Lord, 22 July 2013 - 09:11 PM.
Posted 22 July 2013 - 09:32 PM
More thoughts if you want to go down the Win32 route:
C++ is probably the worst possible language choice for doing this kind of stuff. If you're doing it just to learn about dynamically created controls, fine, but just create child windows on your application window which are common controls, have a look at this simple example:
You have to handle all the control messages yourself in your Windows Procedure. The DLGTEMPLATEEX stuff allows you to handle dialog messages but it's harder to create the initial dialog.
There is probably a better way to do what you want anyway. Instead of using a variable number of controls, use a single ListControl, with multi-columns, one row for each item you need. If you need to create extra entries at runtime, have a button to add a row to the listbox. Double clicking a row in the listbox brings up a dialog which allows editing of that row (and only that row), this dialog box will be the same for each row, so easy to handle. Handle the delete key to delete a row from the list control.
Dynamic controls are rarely needed unless you need to create a large variety of different controls at runtime. If you just want to create a bunch of a single type (or group of types) of controls, go the ListControl way every time, with one column for each control in the group you would have created with the dynamic route.
Dunno if I'm explaining myself very well there ;) EDIT: Summary though - ListControl FTW
Edited by Paradigm Shifter, 22 July 2013 - 09:35 PM.