When installing VC 6.0, there is a installation option to register the environment variable, popped up in the form of a dialog, the default is not installed, so that when installing the QT, it will not be compiled, this option is mainly used Supported by the compilation of the command line. After this selected, you can compile it normally. Under Windows is better than Linux, it is: Most of the installation will not have problems.
Some of the problems below is from elsewhere, I don't know if it is wrong, for use.
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. Selection of the primary component. Generally we program the class as the primary component using the inherited Qwidget class, this is of course not thick Not. But when you make a typical multi-document and single document programs, we have a better choice of the -QmainWindow class, which can easily manage the Menu toolbar main window and status bar, and when the form geometry changes Can perfectly realize the scaling of internal components, which is more convenient than using traditional geometric layout classes, and don't write code. For details, please check the qt gang group documentation, here is not described.
8. Add Checked items in the menu item. In QT, add Checked in the menu item, a bit trouble, the specific write is as follows: 1> Define the INT member variable, and write in the creation menu item: DisplayGeometryMode = New qpopupmenu (this); / / here to create pop-up menu set displayGeometryModem_menuIDWire = displayGeometryMode-> insertItem ( "Wire", this, SLOT (slt_Change2WireMode ())); .// create pop-up menus child 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: Using geometric layouts require 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