iGpsNav = (IGPSNav*)iGpsNavInt;
_EDEBUG(―iGpsNav:‖< IGPSNav* iGpsNav; //把此句申明放在类的private:下就可以解决问题 bool ok; ok = findGpsNav(groupId,iGpsNav); _EDEBUG(―iGpsNav:‖< ============================================================= QPushButton{ background-color: rgba( 255, 255, 255, 50% ); } 透明度50% =================================== 1.问题1: connect函数不存在 对象没有从QObject继承. 2.问題2 采用Event方法连接,在对象方法里启动定时器,在运行时发生: QT timers cannot be started from another thread 解决: 采用Signal/Slot并且连接方式采用 Qt::QueuedConnection 3.利用Signal/Slot删除对象本身: 解决: 采用Signal/Slot并且连接方式采用 Qt::QueuedConnection,这时在另一个对象中就可以删除对象本身了 =========================================================== 用qss增加每个菜单项的高度 在用StyleSheet美化QMenu时,如何指定菜单项与快捷键的间距? QMenu::item { border: 1px solid transparent; margin: 0px 2px 0px 2px; padding: 2px 9px 2px 30px; // Top Right Bottom Left(用这种方式能增加menu中每一行的高度,这就使得在小的触摸屏上进行菜单项的选择的时候,不会那么困难了) } ===================== QGraphicsView无法接收到一些widget传过来的消息的处理方法: bool event ( QEvent * event ) { if(event->type()==QEvent::MouseButtonPress) { QMouseEvent *ke = static_cast return QGraphicsView::event(event); }; ========================================================== 基于Signal/Slot机制的接口写法: MyInterface: public QObject{ //QObject子类都可以 Q_OBJECT public: explicit MyInterface(QObject* parent = 0); //防止出现异常 显式 virtual ~MyInterface(){} virtual void myFunc(int i) = 0; //纯虚函数 //…. signals: void mySignal(int i); //…. public slots: virtual void mySlot(){//do nothing}; private: //… } MyImpl:public MyInterface{ Q_OBJECT public: MyImpl(parent = 0); virtual MyImpl(){}; virtual void myFunc(int i){emit mySignal();}; public slots: void mySlot(){//my code}; } MyImpl2:public MyInterface{ Q_OBJECT public: MyImpl(parent = 0); virtual MyImpl(){}; virtual void myFunc(int i){emit mySignal();}; public slots: void mySlot(){//my code}; } IMyInterface& createMyImpl1(parent = 0) { return * new MyImpl1(parent); } IMyInterface& createMyImpl2(parent = 0) { return * new MyImpl2(parent); } ======================================================== 析构函数 前一定要加 virtual ================================ Aggregation,Composition和Dependency (Star UML) 两个类之间的关系,例如类A和B。 如果B是A成员变量,而且B在A的构造函数中生成(new),那么就是Composition(组合)。 如果B是A成员变量,而且B不在A的构造函数中生成(new),而是在有需要的时候才new,那么就是Aggregation(聚合)。 如果A在某个函数中使用了B作为局部变量,那么就是Dependency(依赖)。 ====================================== 如果有对某一对象的事件进行Bind操作,记得在自己对象构造时进行UnBind操作; =========================================== QtDemo中的单例写法 定义文件 menumanager.h: class MenuManager : public QObject { Q_OBJECT public: static MenuManager *instance(); virtual ~MenuManager(); private: MenuManager(); static MenuManager *pInstance; }; 实现文件 menumanager.cpp #include ―menumanager.h‖ MenuManager *MenuManager::pInstance = 0; //此句不要少了 MenuManager * MenuManager::instance() { if (!MenuManager::pInstance) MenuManager::pInstance = new MenuManager(); return MenuManager::pInstance; } MenuManager::MenuManager() { //构造函数 } MenuManager::~MenuManager() { //析构函数 } 调用方法: MenuManager::instance()-> ============================ Err: ―A does not name a type‖ class B{ public: A hello; B(){} ~B(){} }; class A{ public: A(){} ~A(){} }; I get the error ―A does not name a type‖ when declaring A hello. 解决方法 在 calss B前加个calss A ; ====================================== 要用到模板时,请把定义文件与实现文件写在同一个文件*.hpp中 ============================================================== 定时器: int timeOutTimeId; timeOutTimeId=0; timeOutTimeId = startTimer(1000); if (timeOutTimeId != 0) { killTimer(timeOutTimeId); timeOutTimeId = 0; } void timerEvent(QTimerEvent *event) { if (event->timerId() == timeOutTimeId ) { emit loginStatus(2); killTimer(timeOutTimeId); timeOutTimeId = 0; } } =========================== QMYSQL3: Unable to fetch data Mysql安装目录bin下的库文件 libmySQL.dll 的问题:mysql5.1的库有问题,用mysql5.0的可以 =============================== QString 与QByteArray的转换 QString str; QByteArray byteAry; byteAry = str.toUtf8(); str = QString::fromUtf8(byteAry.data()); ======================================= win32: LIBS += -lws2_32 \\ -lboost_system-mgw34-mt-1_37 \\ -lboost_thread-mgw34-mt-1_37 \\ -lboost_filesystem-mgw34-mt-1_37 \\ -liconv.dll \\ -lrasapi32 \\ -lqjson \\ -llog4cpp \\ -lwsock32 注:-llog4cpp 这行必须要放在-lwsock32 前一行 log4cpp的封装单元在public目录下abclog.h 用法: ABCLog::log.error(―你好‖); ABCLog::log.error(QObject::tr(―测试打印Qstring‖).toUtf8().data()); ABCLog::log.debug(―debug你好‖); ABCLog::log.info(―info‖); ABCLog::log.info(―%s:%s‖,‖你好‖,‖daemon‖); ABCLog::log.info(―%s:%s‖,QObject::tr(―Qstring打印‖).toUtf8().data(),‖daemon‖); ABCLog::log.error(QObject::tr(―wq w w w 你人我人000″).toUtf8().data());