What lib to use for something like this?

Started by
5 comments, last by noatom 10 years, 9 months ago

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?

Advertisement

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?

Desktop.Is the qt api hard to learn?

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:

http://www.codeproject.com/Articles/13330/Using-Dialog-Templates-to-create-an-InputBox-in-C

... 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).

"Most people think, great God will come from the sky, take away everything, and make everybody feel high" - Bob Marley

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.

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:

http://www.winprog.org/tutorial/app_one.html

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.

BUT...

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

"Most people think, great God will come from the sky, take away everything, and make everybody feel high" - Bob Marley

Ah nevermind,project abandoned:)

This topic is closed to new replies.

Advertisement