Results 1 to 7 of 7

Thread: SDI Applications and MainWindow

  1. #1
    Join Date
    Jul 2016
    Posts
    57
    Thanks
    4
    Qt products
    Qt5
    Platforms
    Windows

    Question SDI Applications and MainWindow

    I have a little confusion here.

    If I want to have SDI application, does it mean that all I have to do is the following?:
    Qt Code:
    1. MainWindow w;
    2. w.show();
    To copy to clipboard, switch view to plain text mode 

    So by doing the above code does it mean that I have a true SDI application with "document/view" architecture?

    I did take a look at example here http://doc.qt.io/qt-5/qtwidgets-main...-main-cpp.html
    And it seems that they are doing more checking/manual (i.e. code) addition of widgets, but it seems that its pretty much same as my code above, to initiate the SDi appllication.

    Or for example, in QtCreator, if I start new project, and choose a QMainWindow as a starting class, does it mean that I just created the base SDI application?

    (I'mvery new to Qt)

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: SDI Applications and MainWindow

    If I want to have SDI application, does it mean that all I have to do is the following?:
    No. All that that code gets you (assuming MainWindow is derived from QMainWindow and you have placed it in a properly declared main() function with a QApplication and a call to QApplication:: exec()) is an empty QMainWindow instance on screen. It has empty menus, toolbar, and status bar and nothing as a central widget.

    Qt is not MFC. It has no general concept of a "document" class; if you want to have a central place to store information about your app, you can invent whatever you want as a "document" class to hold that information. If you derive it from QObject, you can declare signals and slots for it so it can communicate with your Qt GUI just like any other QObject-based Qt class, or you can make it a plain old C++ class with an instance owned by MainWindow. In that case, any "communication" is done through signals and slots you declare for MainWindow, and MainWindow reads and writes to the document instance through its C++ methods.

    Here is a basic QMainWindow "SDI" tutorial. In this example, the "central widget" is not a stand-alone QWidget-based class (i.e. not a named class derived from QWidget, just plain old QWidget used as a container), but is built using Qt Designer directly into the QMainWindow-based "Notepad" class. This is simple, but many real Qt apps create a separate class with its own .cpp, .h. and .ui files and set an instance of that as the main window's central widget. It's cleaner that way.

    Also in this tutorial, the QTextEdit class serves as both a GUI widget for editing the "document" as well as the "document" itself since it internally creates a QTextDocument instance and uses it to store what the user is typing. This is fine if all your app needs to store is text, but most real apps need more than that.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  3. #3
    Join Date
    Jul 2016
    Posts
    57
    Thanks
    4
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: SDI Applications and MainWindow

    Quote Originally Posted by d_stranz View Post
    if you want to have a central place to store information about your app, you can invent whatever you want as a "document" class to hold that information.
    In a nearby thread where I made a CTester class here http://www.qtcentre.org/threads/6644...w-and-my-class
    does it mean that I "invented" the "SDI" concept there, so my CTester class is a "document", correct?

    Quote Originally Posted by d_stranz View Post
    or you can make it a plain old C++ class with an instance owned by MainWindow. In that case, any "communication" is done through signals and slots you declare for MainWindow, and MainWindow reads and writes to the document instance through its C++ methods.
    Again, this is how I implemented my CTester, right?

    In that case, what I did there was a "tiny" minimal SDI application?

    And another question is, what about the MDI then? Same thing? Except that I can instantiate my CTester tied to some control widget multiple times? Or any other notable differences?

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: SDI Applications and MainWindow

    Yes, if your CTester class holds all the "document" data, then for all intents and purposes it is the "document".

    So if you need multiple documents you need multiple instances of that class.

    Cheers,
    _

  5. #5
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: SDI Applications and MainWindow

    does it mean that I "invented" the "SDI" concept there, so my CTester class is a "document", correct? ... In that case, what I did there was a "tiny" minimal SDI application?
    Yes, that's basically correct. You have one MainWindow instance and one CTester instance, so this combination is a "single document interface" with a tiny "document".

    And another question is, what about the MDI then? Same thing?
    So in an MDI app, there are "multiple documents" which are often independent of each other. So, each QMdiSubWindow (a typical GUI element for an MDI app) would have its own "document" instance, in your case, its own CTester member variable. Each of these CTester instances are independent, so setting the parameter on one of them has no effect on any other instance.

    Depending on the nature of your app, the MainWindow class might have its own "document" which keeps track of all of the other "documents" in the MDI windows. Think of a C++ project - each MDI window contains a source code file that is edited independently of the files in the other windows, but the MainWindow owns the C++ project to which all of the source files belong. An MDI window needs to be able to tell the main window that the document has changed, and the main window needs to tell the MDI windows to save their documents when the user clicks the "build" button.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  6. #6
    Join Date
    Jul 2016
    Posts
    57
    Thanks
    4
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: SDI Applications and MainWindow

    thanks anda_skoa and d_stranz for explanations,

    By the way, I was programming with MFC before, I'm not a professional MFC programmer neither did any big project there, just relatively simple GUI programs to control my hardware. But now since I'm getting into Qt, I already see that it is so much easier, even simple programs in MFC were pretty big, with those extra functions doc/view architecture thing , message maps and debugging them was already not easy.

    So far Qt concept, especially this non-enforced doc/view thing for SDI/MDI looks just great, and I also like its very simple IDE

  7. #7
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: SDI Applications and MainWindow

    Likewise, I programmed in MFC for 15 years, since it was first introduced in 1992. Switched to Qt in 2007 and will never, ever go back. Qt has its quirks, too, but once you understand those it is so much easier to build modular applications that are easily maintained and changed without having to rip everything out and start over.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

Similar Threads

  1. Replies: 0
    Last Post: 6th November 2011, 09:22
  2. using GPU with Qt applications
    By budda in forum Qt Programming
    Replies: 7
    Last Post: 25th August 2011, 09:02
  3. Replies: 1
    Last Post: 12th April 2011, 09:53
  4. What to use for web applications?
    By szisziszilvi in forum Newbie
    Replies: 1
    Last Post: 7th April 2011, 07:25
  5. Qt applications and USB
    By pocketchange in forum Newbie
    Replies: 2
    Last Post: 11th March 2011, 05:16

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.