开发者

What are the basics concepts in Nokia Qt?

What are the basics concepts in Nokia Qt?

What are t开发者_StackOverflow社区hings I want to know before entering in to Nokia Qt framework?

Could any one help me?

I'm very new for Nokia Qt. Thanks in advance.


Qt is a huge framework, with libraries for handling the GUI, network, database, and all sorts of things. It is very well documented, so go have a look at How to Learn Qt on Nokia's website. That being said, here are some of the basic concepts:

  1. Qt is a framework. This means you organize your code around responding to events. Most importantly, you do not have a "main loop". Your main generally looks like this:

    QApplication app(argc, argv);
    MyMainWindow win;
    
    win.show();
    
    return app.exec();
    
  2. Signals and slots. Qt uses the concepts of signals and slots to connect different parts of a program in a radically decoupled way. You must first connect a signal to a slot:

    connect(sender, SIGNAL(theSignal(int)), receiver, SLOT(theSlot(int)));
    

    Then, when ever the sender "emits" the signal (using, for example, emit theSignal(0)), then Qt arranges for receiver->theSlot(0) to be called. This arrangement is achieved by the "meta-object compiler", a separate program that generates code that you compile and link in to your program.

    Qt uses signals and slots to respond to GUI events. So when you decide what your program needs to do when the user clicks the "File->Open" menu item, you write a slot. Qt uses the meta-object compiler (moc) to pre-process your code and generate lots of machinery behind the scenes to make sure this slot can be connected to signals. In the header for MyMainWindow, you will have something like:

    class MyMainWindow : public QMainWindow
    {
         Q_OBJECT
      public:
         MyMainWindow();
      public slots:
         void on_fileOpen_activated();
      signals:
         void mySignal(int n);
    };
    

    The Q_OBJECT macro is necessary for the moc to recognize the class and generate all the machinery for you. As far as your code is concerned, a slot is just a normal method. It can be public, protected, or private. It can be called normally. The only difference is that you can use connect to connect a signal to it.

    Signals are a different matter. The moc implements all of your signals for you, so, continuing the above example, MyMainWindow.cpp would not include a definition of mySignal.

Qt is a very large framework, and you can easily use only the pieces you need. Go slow. Don't worry about the advanced features, or things that seem too difficult. Figure out what you want to do, then try to do that. Search online. Qt has some of the most extensive documentation out there. Good luck!


As long as you understand Object Oriented Programming, you will pretty much know enough to get started. The main addition to C++ objects from Qt is the Signals and Slots. if you read the documentation, they will start to make a lot of sense quickly.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜