• 12432阅读
  • 8回复

【提问】怎么样使用moc [复制链接]

上一主题 下一主题
离线gaoyu
 
只看楼主 倒序阅读 楼主  发表于: 2005-12-28
我要创建一个用户槽,下面是我的cpp文件:
#include "slot.h"

class MyMainWindow:public QWidget
{
     Q_OBJECT
     public:
           MyMainWindow();
     public slots:
           int MyExitSlot();   //声明的用户槽
     private:
           QPushButton *b1;
           QPushButton *b2;
           QPushButton *b3;
           QLineEdit *ledit;
};

MyMainWindow::MyMainWindow()
{
     setGeometry(100,100,400,200);
     
     b1=new QPushButton("Click here to mark the text",this);
     b1->setGeometry(10,10,350,40);
     b1->setFont(QFont("Times",18,QFont::Bold));
     
     b2=new QPushButton("Click here to cut the text",this);
     b2->setGeometry(10,60,350,40);
     b2->setFont(QFont("Times",18,QFont::Bold));
     
     b3=new QPushButton("Click here to remove the text",this);
     b3->setGeometry(10,110,350,40);
     b3->setFont(QFont("Times",18,QFont::Bold));
     
     ledit=new QLineEdit("This is a line of text",this);
     ledit->setGeometry(10,160,350,30);
     
     //The following three lines connects each button to a predefined slot on
     //the ledit object.Test the program to find out what happens
     connect(b1,SIGNAL(clicked()),ledit,SLOT(selectAll()));
     connect(b2,SIGNAL(clicked()),ledit,SLOT(MyMainWindow::MyExitSlot()));
     connect(b3,SIGNAL(clicked()),ledit,SLOT(clear()));
}

int MyMainWindow::MyExitSlot()     //定义用户槽
{
     exit(0);
}

int main(int argc,char **argv)
{
     QApplication a(argc,argv);
     MyMainWindow w;
     w.show();
     a.exec();
     return 0;
}

头文件:
#include <qapplication.h>
#include <qwidget.h>
#include <qpushbutton.h>
#include <qfont.h>
#include <qlineedit.h>
#include <qstring.h>
#include <stdlib.h>



请问如果我要编译这个文件,需要怎么实现?
怎么使用moc?

谢谢各位大侠
离线tingxx

只看该作者 1楼 发表于: 2005-12-28
用qmake不行吗?
QT自带的文档真是个好东西
一定要好好看呀
离线XChinux

只看该作者 2楼 发表于: 2005-12-28
请查看C/C++ & Qt releated Development版里的KDE Programming版块中的KDE/Qt2编程系列摘录中的第二章,里面有详细讲到如何手工进行编译(不使用qmake)。
二笔 openSUSE Vim N9 BB10 XChinux@163.com 网易博客 腾讯微博
承接C++/Qt、Qt UI界面、PHP及预算报销系统开发业务
离线zccmin
只看该作者 3楼 发表于: 2006-01-17
我怎么没找到你说的手工编译方法呢?
给个连接。
还有,为什么不用qmake?
离线XChinux

只看该作者 4楼 发表于: 2006-01-17
下面是引用zccmin于2006-01-17 15:57发表的:
我怎么没找到你说的手工编译方法呢?
给个连接。
还有,为什么不用qmake?


上KDE Programming版查找
二笔 openSUSE Vim N9 BB10 XChinux@163.com 网易博客 腾讯微博
承接C++/Qt、Qt UI界面、PHP及预算报销系统开发业务
离线cavendish

只看该作者 5楼 发表于: 2006-02-07
建议直接使用qmake/tmake就可以忽略moc的操作了
自己手工调用moc的方式太古老了
在examples里面自己找找吧
离线xuewan

只看该作者 6楼 发表于: 2006-03-05
我也不会用moc,我用的是Kdevelop2.01环境,建立的KDE Mini工程,又加入了qt的ui,然后在KDE Mini工程的类里继承了qt的ui里的Form类,并且在这个新类里建立了自己的槽,用的是moc sample.h -o sample.ui,接着在sample.cpp里加入了#include <sample.moc>,但是一编译就出错啊,请问楼主这是怎么回事啊?另外可否,介绍一下Kdevelop2.01环境下,怎样使用moc.
离线xuxinshao

只看该作者 7楼 发表于: 2006-03-06
在命令行下输入moc yourfilename.h -o moc_youfilename.cpp
离线wxg0130

只看该作者 8楼 发表于: 2009-03-02
没研究过,都是使用qmake
Everything is Nothing
快速回复
限100 字节
 
上一个 下一个