1. How to join OpenGL support in the QT program. Joining OpenGL support in the QT program is simple, just add "-lgl -lglu" in the KDevelop connection library, if you need GLUT support, you can also add "-lglut". The specific operation is to press "F7" in the KDevelop integration compilation environment. Select "Linker" in the pop-up dialog box, enter the library you want to add in the input field, and the writing is consistent with GCC / G . Generally use OpenGL in class QGLWidget, calling this class file is QGL.h, please refer to Gear, Texture, Box in the QT routine (in Redhat7.2, they in redhat7.2, they are / usr / lib / qt -2.3.1 / Doc / Examples under.
2. Check if the Linux / UNIX environment supports the QGLFormat class in OpenGL.QT to help us to easily check if the system supports OpenGL, load the header file (#include
3. Get high and wide. Generally we can obtain some information about the system through QT's QAPPLICATION class, load the header file (#include
4. About signal and grooves. Signals and slot mechanisms are important features of QT libraries, you can not tell it if it doesn't understand QT. This mechanism can establish a convenient and fast communication connection between all kinds of communication, as long as the class is loaded with Q_Object macro The Connect function is connected correctly. The specific way is not described here. But I found this mechanism during use, it is easy to destroy the structure and encapsulation of the program, and the speed is not very satisfied, especially in more When the class is called. The opinion of a hole is that the signal and groove mechanism cannot be used, but it is not much more.
5. Description of the interface in the DT program. Although KDevelop is an excellent integrated compilation environment, it is unfortunate that it is not a visual compilation environment, so there is QDesigner to help us complete the interface design, the program is very simple, use After VB, VC, and Delphi programmers can make a quick way of operation, the operation is completed, the save will generate a file that extension "UI", your next task is to parse it into a CPP and H file, assume the file name For MyForm.UI, the parsing method is as follows: $ uic myform.ui -i myform.h -o myform..cpp // This sentence generates a CPP file $ uic myform.ui -o myform.h // This sentence generates H file.
6. Generate makefile by the Pro file. For Linux / UNIX programmers, writing a Makefile file is an annuatative task, and Qt programmers have no such trouble, a $ qmake -o makefile myprogram.pro can be easily Happy completion tasks, and the PRO file is also easy, its core is a simple list of H and CPP files. Please refer to the samples and tutorials of QT (in redhat7.2, it is in / usr /LIB/QT-2.3.1/doc/examples under the relative to the Makefile file, there is no difficulty.
7. The choice of the main component. Generally we programmatically use the class inherited Qwidget class as the primary component, which is certainly not thick. But we have a better choice when making a typical multi-document and single document programs. It is convenient to manage the menu toolbar main window and status bar, and the internal components can be fully scaled when the form geometric property changes, which is much easier to manage with traditional geometric layouts. And don't write code. For details on it, please consult the QT to help group documentation, here you have not described. 8. Add Checked items in the menu item. In QT, add Checked in the menu item, a bit trouble, the specific way is as follows: 1> defines the type int member variable, and create a menu item write: displayGeometryMode = new QPopupMenu (this); // here to create pop-up menu set displayGeometryModem_menuIDWire = displayGeometryMode-> insertItem ( "Wire", this, SLOT (slt_Change2WireMode ()) ) ;.// Create a pop-up menu subkey DISPLAYGEOMETRYMODE-> setItemChecked (m_ menuidwire, true); // Set this subkey is selected
2> Write again in the groove function: DisplayGeometrymode-> setItemChecked (m_menuidwire, false); // This subkey is set as a non-selected state
9. The intercept program is about to exit. Sometimes we need to perform some processing, such as saving files, etc. when the program is about to exit. How to intercept the signal to exit? Or use the qapplication class AboutToquit () signal, program It can be written like this: Connect (QAPP, Signal (AboutToquit ()), this, slot (Slot_SaveAction ())); on the slot function slot_saveActions () can be related, pay attention, using the global object QAPP needs to load the head file (# INCLUDE
10. Popked the Standard File dialog. The pop-up file dialog box is easy to handle. For example, QString filter = "txt files (*. Txt) / n" // set file filtering, default display text file " All files (*) "; // Optional display All file qstring filepathname = qfiledialog :: getopenFileName (" ", filter, this); // Pop up dialog, this sentence needs to load head file (#include
12. Setting the subclass of the timer All QObject does not have to load a QTIMER object when setting the timer, because this causes resource waste and needs to write excess functions, it is very inconvenient. The best way is to overload the TimeRevent function, specific worded as follows: class Gui_DlgViewCtrlDatum: public QDialog {Q_OBJECTpublic: Gui_DlgViewCtrlDatum (QWidget * parent = 0, const char * name = 0, bool modal = FALSE, wFlags fl = 0); ~ Gui_DlgViewCtrlDatum (); protected: void timerEvent (QTimerEvent *) }; void gui_dlgviewctrldatum :: timerevent (QTIMEREVENT * E) {// statements} Set time interval in the constructor of GUI_DLGVIEWCTRLDATUM: StartTimer (50); // unit is in milliseconds, every 50 milliseconds, the function TIMEREVENT will Call once.
13. The most convenient geometric layout QGridLayout In the geometric layout of Qt, the author believes that QGridLayout is most convenient, for example: QGridLayout * Layout = New QGridLayout (this, 10, 10); // Create a 10 * 10 QGridLayout Example Layout-> addMulticellWidget (GUI_DLGSLAB_GLWND, 1, 8, 0, 7); // Fix the OpenGL window (1,0) cells in QGridLayout (1,0) cells in (8, 7) cells in Layout-> AddMulticellWidget (Slider1, 0, 9, 8, 8); // Fixed a slider in cell (0, 8) to (9, 8) Layout-> AddWidget (UplimitLBL, 1, 9); // Put a Label (UplimitLBL) Fixed in cells (1, 9), regardless of how the form is changed, their layout does not change, which is more convenient than repeated use qvboxLayout and QHboxLayout. Note: Use geometric layouts to need to call heads Document (#include
QStringList is a less common class, which can see a linked list of QString (QT) The function of the latch chain class QLIST is applicable, its single node is the qstring type), especially suitable for processing text, one piece below It can be seen that it is convenient and quick: qstring stramp = "ABC | B | C | D"; QStringList strlsttmp; strlsttmp = qstringlist :: split ("|", strtmp); for (unsigned int = 0; i