1+1=10

记记笔记,放松一下...

Link Confilict between SDL and Qt under Windows

Someone complain that, when using SDL and Qt in the same project under Windows, the linker will generate link error.

SDLmain.lib(SDL_win32_main.obj):-1: error: LNK2005: _WinMain@16 already defined in qtmaind.lib(qtmain_win.obj)

What happened behined this?

1
2
3
4
5
6
#include <QApplication>
#include <SDL …

Redirect current process's stdout to a Widget such as QTextEdit

Note:

  • Source code can be got from https://github.com/dbzhang800/StdoutRedirector
  • This class can only be used in Qt5, as QWindowsPipeReader which is introduced in Qt5.0 is used.

Implementation

Windows

  • Normally, we need to create pipe with CreatePipe(), then attach stdout to it's write end with SetStdHandle(), then …

Qt Macro: Q_DECLARE_INTERFACE

Q_DECLARE_INTERFACE(InterfaceClassName, InterfaceId)

This macro associate the given InterfaceId to the interface class called InterfaceClassName.The macro is normally used right after the interface definition:

1
2
class MyInterface {};
Q_DECLARE_INTERFACE(MyInterface, "me.debao.qt.myinterface")

Q_DECLARE_INTERFACE is a macro that defines helper function that make qobject_cast(QObject *object) return a …

Qt Macro: Q_DECLARE_METATYPE

QMetaType

  • It associates a type name to a type ID, enabling construction and destruction to occur dynamically at runtime.
  • QMetaType is used as a helper in QVariant and queued signals and slots connections.

example1:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16 …

Qt Macro: Q_DECLARE_TYPEINFO

Definition

Q_DECLARE_TYPEINFO is used to specialise a template class called QTypeInfo.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
#define Q_DECLARE_TYPEINFO_BODY(TYPE, FLAGS) \
class QTypeInfo<TYPE > \
{ \
public: \
    enum { \
        isComplex = (((FLAGS) & Q_PRIMITIVE_TYPE) == 0), \
        isStatic = (((FLAGS) & (Q_MOVABLE_TYPE | Q_PRIMITIVE_TYPE)) == 0), \
        isLarge = (sizeof(TYPE …

screen.css used by octopress

screen.css

The css file used by octopress blog with the default theme is called screen.css, which locates in source/stylesheets/screen.css.

screen.scss

The screen.scss file, which locates in sass/screen.scss, is used to generate the above css file.

 1
 2
 3
 4
 5
 6 …

My first C Extension To Numpy

A Simple Example

Let's create an extension module called opee and let's say we want to create a Python interface to one C function example. This function takes a numpy array as argument and return an integer. We want this function to be callable from Python as follows:

1
2 …

Sandbox: For Octopress Usage and Markdown Syntax Test

Note: I had switched from Octopress to Pelican since 2015, so this page is not valid any more. Contents in this pages had been changed in order to make pelican happy.

Table Test

Source Code:

1
2
3
4
5
6
Left Aligned Header | Center Header | Right Aligned Header
:-------------------|:-------------:|--------------------:
Cell …

Setup and Configure My Octopress Blog

I am using Mac OS X 10.8, Ubuntu 12.10 and Windows Vista at present. I want to have a simple blog which can be coutrolled by myself …

Install Ruby 1.9.3

Octopress depends on Ruby 1.9.2 or newer.

Mac X 10.8

The Ruby provided …

VirtualBox的网络设置

VirtualBox 可以为每一个Guest分配多达8个网卡(界面上只显示了4个,其他需要通过VBoxManager modifyvm进行配置),每个网卡的连接方式可以选为下列之一:

  • Not attached
  • NAT
  • NAT Network
  • Bridged Adapter
  • Internal Network …