Recently, I encountered a project that requires QT for interface development. I remember the last time I used QT, it was two years ago. At that time, qt3 was quite comfortable to use. But now I have installed qt4 to know that QT has changed a lot. The usage of UIC and qmake has changed. So it took an afternoon to adapt to the new environment.
First, read the following blogs. Basically, there is a general idea.
Http://blog.csdn.net/sgnaw/article/details/2595389
Http://www.cnblogs.com/bigshow/archive/2008/10/23/1318267.html
Http://blog.csdn.net/apple1985507/article/details/5387125
With a general idea, however, relying on the above blog, we still cannot call a test program. After one afternoon's efforts, we finally found a solution. Summary.
1,
The qdialog header file of qt4 is compiled by C ++. Therefore, when declaring the file, use # include <qdialog> instead of # include <qdialog. h>. Otherwise, qdialog will appear during compilation. h does not exist;
2. When you re-use the original UI file (that is, directly open the existing UI file), you need to delete the run make clean generated by make, delete the original executable file ,. pro files, makefile files ,. h file.
When adding a new signal slot: perform the following operations,
1. Generate a. h file from the new. UI file (eg, form1.ui-> form1.h)
2. Declare the header file (# include <qmessagebox> and custom slot eg: Public slots: void showinfo () in mydlg. h ();
3. Declare the connection of the signal slot in the mydlg constructor in mydlg. h and implement this signal.
Eg:
Qobject: connect (ui. pushbutton_2, signal (clicked (), this, slot (showinfo ()));
Void mydlg: showinfo ()
{
Qmessagebox: Information (this, TR ("hello"), TR ("Hello World"), TR ("OK "));
}
4. Run qmake again to compile and run the program;
Now, you can implement more complex functions by redefining more complex slots. Good luck.