关于Cocoa与Qt完美混编

关于Cocoa与Qt完美混编,第1张

概述最近在研究关于Mac下面的全局的鼠标键盘事件,并捕捉鼠标划词的功能 以下是关于Qt开发部分代码: #include "mainwindow.h"#include <QApplication>#include "mainwindow.h"#import <Cocoa/Cocoa.h>@interface KeyLoggerApplication : NSApplication{

最近在研究关于Mac下面的全局的鼠标键盘事件,并捕捉鼠标划词的功能

以下是关于Qt开发部分代码:

#include "mainwindow.h"#include <QApplication>#include "mainwindow.h"#import <Cocoa/Cocoa.h>@interface KeyLoggerApplication : NSApplication{                                      }  @end  @implementation KeyLoggerApplication  - (BOol)sendEvent:(NSEvent *)anEvent {    NSEventType type = [anEvent type];    bool handled = NO;    if (type == NSKeyUp)    {        switch( [anEvent keyCode] )        {        default:            NSLog(@"Keypressed: %d,**%@**",[anEvent keyCode],[anEvent characters]);            break;        }    }else if(type == NSMouseMoved)    {        NSLog(@"Mouse: %@**",[anEvent characters]);    }    //handle only the keys i need then let the other go through the regular channels    //this stops the annoying beep    if( !handled )        [super sendEvent:anEvent];}- (voID)applicationDIDFinishLaunching:(NSNotification *)aNotification{    [NSEvent addGlobalMonitorForEventsMatchingMask:NSleftMouseDownMask | NSRightmouseDownMask | NSMouseMovedMask | NSleftMouseDraggedMask | NSRightmouseDraggedMask handler:^(NSEvent *event)    {        Nsstring *text;        NSInteger delta;        NSLog(@"applicationDIDFinishLaunching: %s**","NSMouseMoved");        switch (event.type) {            case NSleftMouseDown://                text = [[Nsstring alloc] initWithFormat:@"%d",++leftClicked];//                leftClickedText.stringValue = text;                break;            case NSRightmouseDown://                text = [[Nsstring alloc] initWithFormat:@"%d",++rightClicked];//                rightClickedText.stringValue = text;                break;            case NSMouseMoved:            NSLog(@"NSMouseMoved: %s**","NSMouseMoved");            case NSleftMouseDragged:            NSLog(@"NSleftMouseDragged: %s**","NSleftMouseDragged");            case NSRightmouseDragged://                delta = (NSInteger)sqrt(event.deltaX * event.deltaX + event.deltaY * event.deltaY);//                moved += delta;//                text = [[Nsstring alloc] initWithFormat:@"%d px",moved];//                movedText.stringValue = text;             NSLog(@"NSRightmouseDragged: %s**","NSRightmouseDragged");                break;            default:                break;        }        [text release];    }];}@endint main(int argc,char* argv[]){    [KeyLoggerApplication sharedApplication];    QApplication a(argc,argv);    MainWindow mw;    mw.show();    return a.exec();}
新建一个qt gui应用

pro里加入

mac:{
liBS+= -framework AppKit
}

并且将main.cpp改成main.mm文件


最近在GitHub上面看到一个开源的关于Qt Mix Cocoa的项目,特此引荐Qt与Cocoa混编

总结

以上是内存溢出为你收集整理的关于Cocoa与Qt完美混编全部内容,希望文章能够帮你解决关于Cocoa与Qt完美混编所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1053676.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-25
下一篇 2022-05-25

发表评论

登录后才能评论

评论列表(0条)

保存