Qt interview questions

1. Describe Signals & Slots.

A: Signals ans Slots are used for communication between objects. It shall replace generally way of callbacks to avoid the flaws from callbacks.

    Any class deprived from QObject can have its own signals and slots.

  


2. How Signals & Slots work? What is MetaObject system?
3. Object and signals & slots.
4. QObject related. What class do i need to inherit if i want to have signals & slots?OR Why is QObject a special class?
5. What is O_OBJECT macro? Do you know what it expands into?
6. What are slots?
7. Can i call a slot normally?

A: yes, of course. You can define slot as normal member functions.  You can use identifier public, proteced and private to set the scope of each slots functions.


8. Can slots be virtual?

A: yes, it can be defined as virtual and can be inherited by child class.

     It even can be pure virual like:

    classBaseConfigurationPage:publicQWidget{

// Some constructor and other methods, irrelevant here.

public slots:
      
virtualvoid loadSettings()=0;

  
virtual void saveSettings()=0;

};

classGeneralConfigurationPage:publicBaseConfigurationPage{

// Some constructor and other methods, irrelevant here.

//public slots: do not need this here any more
  
void loadSettings();

  
void saveSettings();

};

      Just like regular c++ pure virtual methods. The code generated by MOC does call the pure virtual slots, but that's ok since the base class can't be instantiated anyway...

      Again, just like regular c++ pure virtual methods, the class cannot be instantiated until the methods are given an implementation.

      One thing: in the subclass, you actuallly don't need to mark the overriden methods as slots. One, they're already implemented as slots in the base class. Two, you're just creating more work for the MOC and compiler since you're adding a (tiny) bit more code. Trivial, but whatever.

 


9. Can i call a Signal normally?

A: no, you can not. only can be emit. (?)


10. Give the syntax/prototype of connect().

A: connect (obj1, SIGNAL(sigFunc(arg...)), obj2, SLOT(slotFunc(arg...)));


11. Can i connect two signals? how?

A: Yes. things work like pass this events from one object to another object.

    --- connect (obj1, SIGNAL(sigFun()), obj2, SIGNAL(sigOtherFunc()));


12. What is the order of calling of slots connected to the same signal?

A: If it is in single process(thread) mode, it shall be called in sequence of the definition of connect.

    Ifi it is in Multiple threads mode, need to check


13. What are the container classes you have used in Qt?

A: QVector, QMap, QList, Q

14. What is the difference between QList, QLinkedList, QVector etc.
15. What is implicit sharing? How Qt uses it.

16. Question: What is the difference between close() and hide() in Qt?
Answer:
1) A close event is sent before the widget closes and can be ignored, in this case the Window won't close. A hide event is sent when the widget has been hidden.
2) close() deletes the closed widget if the WDestructiveClose flag has been set during construction of the widget. If that flag has not been set you have to delete the widget yourself. When you delete the form the widgets on the form will be deleted as well.
Note: A widget receives spontaneous show and hide events when its mapping status is changed by the window system, e.g. a spontaneous hide event when the user minimizes the window, and a spontaneous show event when the window is restored again. After receiving a spontaneous hide event, a widget is still considered visible in the sense of isVisible().

(1) Why Qt does not use templates for signals/slot implementation?
(2) Explain memory management in Qt.

Q. What does SIGNAL() and SLOT() macro expand to?
Q. Does Qt has Garbage collection system?
Q. what is "emit", "slots", "signals"? (are they macro, keyword or function?)
Q. Have you made any custom widget yourself?
Q. What classes does Qt provides to handle XML?
Q. Difference between Dom, SAX, Readers?
Q. How do you use thread classes?
Q. What is QMutex and how do you use it?
Q. Explain Model View framework. And mention one situation where you used it.
Q. How do you communicate between threads?
Q. What is QApplication?
Q. If i create two objects of QApplication what will happen? Why shouldn't i use two?
Q. What is Q_SLOTS? why it is needed? whats the problem in "slots"?

1. where exactly we have to use this following unicode classes
   QString(),
   QByteArray(),
   QTextStream(),
   QTextCodec()

原文地址:https://www.cnblogs.com/simonhaninmelbourne/p/3018480.html