tags:

views:

193

answers:

1

I've got a class I've written, and I'm trying to connect it to Qt. I've got some "best practices" questions I hope you all can help me with.

  • When creating a mainWindow to contain data, I inherit the header file into my custom class specified above, so I can make use of the elements created within Qt Creator. Is this the proper way of doing things? I borrowed this idea from the second chapter of the official book Should I be making a NEW class that binds these together?

  • Inside of the class itself should I be strictly encapsulating data, or making it friendly to like-classes? Does this help with accessability?

  • Aside from the official book's chapter on MVC, and the on-line tutorial here, what are some other resources to a MVC newcomer in Qt?

Thanks in advance

+2  A: 

When creating a mainWindow to contain data, I inherit the header file into my custom class specified above, so I can make use of the elements created within Qt Creator. Is this the proper way of doing things?

I assume that you mean "include the header file": when creating a widget with an associated .ui you should include the uic (created by Qt Creator in your case) generated header file in your widget class' header file, and then you have three options:

  1. Inherit from the uic generated class.
  2. Hold a pointer to said class in your class.
  3. Hold said class in a regular member variable.

I prefer number 3 unless the ui class is really big because it means one less new allocation and results in less coupling.

Inside of the class itself should I be strictly encapsulating data, or making it friendly to like-classes? Does this help with accessability?

You should still apply OO design rules when using Qt. I generally hold the model inside the main window and pass other widgets whatever data they need as interfaces, containers, structs, delegates, etc. Sometimes I pass the entire model.

Aside from the official book's chapter on MVC, and the on-line tutorial here, what are some other resources to a MVC newcomer in Qt?

I have managed to successfuly use MV by reading the official book and using the Qt help together with the examples.

rpg
very straight forward, thank you.
bobby
You're welcome :)
rpg