Skip to content

Instantly share code, notes, and snippets.

View 0xlitf's full-sized avatar

0xlitf 0xlitf

  • 22:50 (UTC +08:00)
View GitHub Profile
@0xlitf
0xlitf / Qt信号槽传递std::tuple
Created March 28, 2016 14:47
Qt信号槽传递std::tuple
typedef std::tuple<QString, QString, QString, QString, QString,
QString, QString, QString, QString, QImage>
PersonInfo;
qRegisterMetaType<PersonInfo>("PersonInfo");
Q_DECLARE_METATYPE( Type) //使自定义类型可以存进QVarient
This macro makes the type Type known to QMetaType as long as it provides a public default constructor, a public copy constructor and a public destructor. It is needed to use the type Type as a custom type in QVariant.
@0xlitf
0xlitf / debug release
Last active March 25, 2016 10:12
debug release
https://msdn.microsoft.com/en-us/library/fsk896zz.aspx?f=255&MSPPError=-2147217396
How to: Debug a Release Build
Visual Studio 2015 Other Versions
You can debug a release build of an application.
To debug a release build
Open the Property Pages dialog box for the project. For details, see Working with Project Properties.
Click the C/C++ node. Set Debug Information Format to C7 compatible (/Z7) or Program Database (/Zi).
@0xlitf
0xlitf / QLabel显示图片保持缩放比
Created March 25, 2016 03:36
QLabel显示图片保持缩放比
m_displayer->setPixmap(QPixmap::fromImage(image).scaled(m_displayer->size(), Qt::KeepAspectRatio));
//1、第一个参数应该为label的size,而不是图片的size
//2、不应该设置setScaledContents(true);
@0xlitf
0xlitf / 如何保证某个函数只被调用一次
Created March 15, 2016 06:53
如何保证某个函数只被调用一次
一个函数caller会在其内部调用另外一个函数callee,现在的情况是,caller可能会在多个地方被多次调用,而你希望callee只在第一次被调用时被调用一次。一般情况下,callee会是一个对环境或者资源的初始化工作。
或许,从代码结构的角度来讲,你第一个想到的是把callee从caller中拿出来,放到某个合适的地方做初始化,这是个不错的方法,但相信我,在有些时候这并不是个有效的办法:你可能无法找个那个“合适的地方”,你也可能找到了但因此而失去lazy initialization的好处~~~。
这里,我只想对这个问题找个好点的方法。
第一个方法很简单,就是用个静态的flag来判断:
@0xlitf
0xlitf / Q_DECLARE_METATYPE与qRegisterMetaType学习.cpp
Created March 15, 2016 01:09
Q_DECLARE_METATYPE与qRegisterMetaType学习
基本理解
Q_DECLARE_METATYPE
如果要使自定义类型或其他非QMetaType内置类型在QVaiant中使用,必须使用该宏。
该类型必须有公有的 构造、析构、复制构造 函数
qRegisterMetaType 必须使用该函数的两种情况
如果非QMetaType内置类型要在 Qt 的属性系统中使用
如果非QMetaType内置类型要在 queued 信号与槽 中使用
二者关系
@0xlitf
0xlitf / mac增加空白图标
Last active March 11, 2016 12:27
mac增加空白图标
添加空白分割区域到 Dock
defaults write com.apple.dock persistent-apps -array-add '{"tile-type"="spacer-tile";}'; killall Dock
添加「最近使用」堆栈到 Dock
defaults write com.apple.dock persistent-others -array-add '{"tile-data" = {"list-type" = 1;}; "tile-type" = "recents-tile";}'; killall Dock
@0xlitf
0xlitf / test.cpp
Created March 8, 2016 08:35
C++调用python时,object.h中变量为slots的问题
//解决办法,在object.h中头文件开始#undef slots 在最后#define slots
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#pragma comment(lib,"C:/Python34/libs/python34.lib")
#include <QtWidgets/QMainWindow>
#include "ui_mainwindow.h"
#include <QDebug>
#include "C:\Python34\include\Python.h"
@0xlitf
0xlitf / oracle数据库的sql语句中不能包含分号
Created March 7, 2016 11:32
oracle数据库的sql语句中不能包含分号
qt程序中oracle数据库的sql语句中不能包含分号
@0xlitf
0xlitf / 64位oracle驱动.cpp
Created March 7, 2016 06:55
64位oracle驱动.cpp
#include "mainwindow.h"
#include <QApplication>
#include <QtGui>
#include <QtSql>
int main(int argc, char **argv)
{
QApplication myApp(argc, argv);
QLibrary *hello_lib = NULL;
@0xlitf
0xlitf / ItemFactory.cpp
Created March 4, 2016 10:29
ItemFactory
#include "ItemFactory.h"
#include <QDebug>
ItemFactory *ItemFactory::instance = NULL;
ItemFactory::ItemFactory(void)
{
}
ItemFactory &ItemFactory::getInstance()