Skip to content

Instantly share code, notes, and snippets.

#include <map>
#include <string>
#include <iostream>
namespace MyNameSpace {
class Base
{
public:
virtual char* GetName() const = 0;
};
@SunRain
SunRain / gist:7174eaa2f8f81202d919
Last active August 29, 2015 14:07
QT根据类名动态创建类对象
http://bbs.csdn.net/topics/340251573?page=2
http://bbs.csdn.net/topics/390480286
@SunRain
SunRain / gist:f1c8481b669655bc2e85
Created October 16, 2014 15:17
Qt-creating-class-dynamically-from-its
http://kunalmaemo.blogspot.com/2010/07/creating-class-dynamically-from-its.html
Some time it could be useful to be able to create new instance of class just by knowing its name. Such as in situation like when you are receiving XML from network and you want to create certain type of parser depending upon XML received from network.
In Qt its possible by using Qt's meta object system.
Here is my sample implementation that uses QMetaType to achieve the same. In sample code Parser is base class of all parser.
class Parser
#include <QObject>
#include <QDebug>
class FactoryBase
{
public:
virtual QObject* create() = 0;
};
QMap<QString, FactoryBase*> factoryMap;
@SunRain
SunRain / gist:6544a95c1167c3d65d46
Created September 23, 2014 09:42
QML手势及多点触摸之PinchArea
http://my.oschina.net/xishvaigo/blog/295855
https://gitorious.org/omap4-v4l2-camera/pages/Home
@SunRain
SunRain / 用Android-X86和VirtualBox打造高性能Android开发环境
Created February 6, 2012 02:02
用Android-X86和VirtualBox打造高性能Android开发环境
http://yuangu.tk/post-32.html
转自:http://www.cnblogs.com/MaxWoods/archive/2011/09/16/2179310.html
不知道有多少Android开发着对Android虚拟机的那悲剧的性能有意见,反正我的看法是:那速度实在是太坑爹了!
为什么Android虚拟机比iOS和WP7的虚拟机要慢很多呢?原因如下:
1. Android 模拟器模拟的是 ARM 的体系结构(arm-eabi),而 iOS 和 WP7 的模拟器的目标体系结构都是 x86 的,另外 iOS 的模拟器中运行的 App 也是编译为 x86 的。这样一来 Android 模拟器需要做一些额外的二进制翻译工作。
@SunRain
SunRain / android:添加usb键盘+按键布局和映射的修改
Created February 5, 2012 14:08
android:添加usb键盘+按键布局和映射的修改
android下的按键布局和映射
这个笔记整理一下使用usb键盘遇到的问题,比如添加usb键盘的keylayout,添加按键,修改按键映射等。
本文参考了:
http://blog.csdn.net/kieven2008/archive/2011/03/26/6279975.aspx
http://blog.csdn.net/skdev/archive/2010/03/08/5355542.aspx
Android的用户输入系统,自下而上,分成如下部分:
@SunRain
SunRain / FileObserver
Created February 5, 2012 12:25
FileObserver
https://developer.android.com/reference/android/os/FileObserver.html
Monitors files (using inotify) to fire an event after files are accessed or changed by by any process on the device (including this one). FileObserver is an abstract class; subclasses must implement the event handler onEvent(int, String).
Each FileObserver instance monitors a single file or directory. If a directory is monitored, events will be triggered for all files and subdirectories (recursively) inside the monitored directory.
An event mask is used to specify which changes or actions to report. Event type constants are used to describe the possible changes in the event mask as well as what actually happened in event callbacks.
Warning: If a FileObserver is garbage collected, it will stop sending events. To ensure you keep receiving events, you must keep a reference to the FileObserver instance from some other live object.
@SunRain
SunRain / adb devices显示no permissions
Created February 4, 2012 05:54
adb devices显示no permissions
以普通用户登录linux,解出android-sdk后,设置环境变量,然后运行adb devices会提示权限不够:
List of devices attached
???????????? no permissions
这是因为访问adb设备需要root权限。
我们可以利用文件的set-user-id属性来解决这个问题: