分类目录归档:QT

终端测试验证工具

http://invisible-island.net/xterm/ctlseqs/ctlseqs.html
http://www.xfree86.org/current/ctlseqs.html
Linux环境下,主要都是泛VT102的终端,以下是vt102终端。
https://vt100.net/docs/vt102-ug/introduction.html
https://vt100.net/docs/vt102-ug/contents.html

VT100,VT101,
参考开源:https://konsole.kde.org/

使用匿名函数,简易地把同步转异步

使用匿名函数,简易地把同步转异步。
大概思路,已经省去了线程池的相关说明。

#define MYASSERT(x)
 
typedef std::function<QVariant(void)> FunAsyncTask;
typedef std::function<void(QVariant)> FunSuccessCallBack;
typedef std::function<void(QVariant)> FunErrorCallBack;
 
//从KAsyncTask派生
class AsyncTask     
{
private:
	const FunAsyncTask task;
	const FunSuccessCallBack ok_cb;
	const FunErrorCallBack err_cb;
        const QPointer<QObject> callerThiz; //外部调用者的This指针,目的利用它来检验当前匿名函数所捕获的参数是否仍有效。
	QVariant result;
	QVariant err;
        //ToDo保存调用线程,调用线程与成功及错误的处理是同一个线程,也即是调用成功及错误之前先检查线程是否相同。
	int threadCallId; //任务请求的线程。
	int threadDoTaskId; //任务处理的线程
public:
	static void post_aync_task(QObject *thiz, FunAsyncTask t, FunSuccessCallBack ok, FunErrorCallBack err)
	{
		AsyncTask *task = new AsyncTask(thiz, t, ok, err);
		//ToDo推送至多线程任务队列。
	}
private:
	AsyncTask(QObject *thiz, FunAsyncTask t, FunSuccessCallBack ok, FunErrorCallBack err)
		: callerThiz(thiz), task(t), ok_cb(ok), err_cb(err)
	{
		threadCallId = GetCurrentThreadId();
	}
 
	void run()
	{
		// AnyncThread do the job.
		threadDoTaskId = GetCurrentThreadId();
		try
		{
			result = task();
			//ToDo Save Ok
		}
		catch (...)
		{
			//TODO Save Error;
		}
	}
 
	void handleResult()
	{
		//ToDo MainThread to do the job.
                MYASSERT(callerThiz);
		MYASSERT(threadCallId == GetCurrentThreadId());
		ok_cb(result);
	}
 
	void handleError()
	{
		//ToDo MainThread to do the Error
                MYASSERT(callerThiz);
		MYASSERT(threadCallId == GetCurrentThreadId());
		err_cb(err);
	}
};
 
void assertValidTaskLambda(char* txt)
{
	//ToDo提取lamda表达式的中括号的参数进行检查,不允许使用"=&"的特殊字符,有该字符则输出错误及抛出异常。
        //提取括号外及大括号前的字符串,不允许"mutable"参数使用。
	printf("\r\n%s", txt);
}
 
void assertValidCallBackLambda(char* ok, char* err)
{
        //ToDo提取lamda表达式的中括号的参数进行检查,不允许使用"&"的特殊字符,有该字符则输出错误及抛出异常。
        //提取括号外及大括号前的字符串,不允许"mutable"参数使用。
	printf("\r\n%s-%s", ok, err);
}
 
#define POST_AYNC_TASK(task, ok_cb, err_cb) \
{\
        assertValidQObject(this);  \
	assertValidTaskLambda(#task); \
        assertValidCallBackLambda(#ok_cb, #err_cb) \
	AsyncTask::post_aync_task(this, task, ok_cb, err_cb); \
}
 
int MyClass::execute()
{
	int x = 1;
	int y = 2;
	int z = 3;
	int m = 4;
 
 	FunAsyncTask task = [x, y, z]()->int{
		return QVariant(123);
	};
 
 	FunSuccessCallBack ok = [x, m](QVariant r){
		printf("ok...ok...%d", r);
	};
 
	FunErrorCallBack err = [z, m](QVariant err){
		printf("failed...failed...%d", err);
	}; 
 
	POST_AYNC_TASK(task, ok, err); //这种使用,报错。
 
	// 推荐以下方式使用,目的是语法检查,减少多线程出错。
        // POST_AYNC_TASK((task_exp),(ok_exp),(err_exp))
        // 如果表达式不用括号包裹起来的话,可能会导致编译出错。
	POST_AYNC_TASK(([x, y, z]()->QVariant{
		int v1 = x;
		int v2 = v1*2;
		Sleep(1000);
		return QVariant(v2 + z);
	}), ([=](QVariant r){
		printf("ok...ok...%d", r);
	}), ([=](QVariant err){
		printf("failed...failed...%d", err);
	}));
 
	getchar();
}

Xperf与ETW脚本

@echo off
pushd %~dp0
set now=%date:~0,4%%date:~5,2%%date:~8,2%_%time:~0,2%%time:~3,2%%time:~6,2%
set now=%now: =0%
echo %now%
set path_current=%~dp0
set path=%path%;%path_current%;%path_current%\wpt
 
set path_result=%path_current%\result
if not exist %path_result% (md "%path_result%")
 
set path_backup=%path_result%\backup
if not exist %path_backup% (md "%path_backup%")
set path_word=%path_result%\wps
if not exist %path_word% (md "%path_word%")
set path_et=%path_result%\et
if not exist %path_et% (md "%path_et%")
set path_ppt=%path_result%\_ppt
if not exist %path__ppt% (md "%path__ppt%")
 
set path_word_result=%path_result%\preread_word.txt
set path_ppt_result=%path_result%\preread_ppt.txt
set path_et_result=%path_result%\preread_et.txt
 
set path_test=%~1
if not exist %path_test%\wpstest.exe (
    echo "the path is wrong......"
    echo "can not find the wpstest.exe by that path."
    goto :exit
)
set softnode=SOFTWARE
IF "%PROCESSOR_ARCHITECTURE%"=="AMD64" set softnode=SOFTWARE\WOW6432Node
reg query "HKLM\%softnode%\kxtry\test\6.0\Common\res">nul 2>nul && call :registry_clear
 
if not exist %path_word_result% (
    echo "ready to do wps preread info."
    pushd %path_word%
    call :dokswpt /kxtry /wps /runactions="sleep,10|closeapp" %path_current%/1.docx
    popd
    copy /Y %path_word%\prereaddata_%now%.txt %path_word_result% > nul 2>nul
) else if not exist %path_ppt_result% (
    echo "ready to do _ppt preread info."
    pushd %path__ppt%
    call :dokswpt /kxtry /_ppt /runactions="sleep,10|closeapp"  %path_current%/1.pptx
    popd
    copy /Y %path__ppt%\prereaddata_%now%.txt %path__ppt_result% > nul 2>nul
) else if not exist %path_et_result% (
    echo "ready to do et preread info."
    pushd %path_et%
    call :dokswpt /kxtry /et /runactions="sleep,10|closeapp"  %path_current%/1.xlsx
    popd
    copy /Y %path_et%\prereaddata_%now%.txt %path_et_result% > nul 2>nul
) else (
    echo "all job was finished."
)
 
echo "finish all..."
goto :exit
 
rem -------------
:registry_clear
echo "remove the preRead's infomation from registry."
reg export "HKEY_LOCAL_MACHINE\%softnode%\kxtry\test\6.0\Common\Res" %path_backup%\backup_%now%.reg /y
reg delete "HKEY_LOCAL_MACHINE\%softnode%\kxtry\test\6.0\Common\Res">nul 2>nul /f
reg delete "HKEY_CURRENT_USER\Software\kxtry\test\6.0\Common\Res" >nul 2>nul /f
goto :exit
 
 
rem --------
:dokswpt
xperf -stop app_session -d app_tmp.etl
xperf -stop -d base_tmp.etl
if exist app_tmp.etl (del app_tmp.etl)
if exist base_tmp.etl (del base_tmp.etl)
 
echo "open session.."
xperf -start -on Base
xperf -start app_session -on CA80A0D7-6CA2-4F62-B22D-D0F88D79AE4B
echo "%path_test%\wpstest.exe" %*
call "%path_test%\wpstest.exe" %*
 
xperf -stop app_session -d  app_tmp.etl
xperf -stop -d base_tmp.etl
xperf -merge base_tmp.etl app_tmp.etl kxtry_%now%.etl
 
xperf -tle -i kxtry_%now%.etl -o hardfaults_%now%.csv -a hardfault -file -bytes
xperf -tle -i kxtry_%now%.etl -o time_%now%.csv -a dumper -provider {CA80A0D7-6CA2-4F62-B22D-D0F88D79AE4B}
xperf -tle -i kxtry_%now%.etl -o pagefaults_%now%.csv -a dumper -provider {3D6FA8D3-FE05-11D0-9DDA-00C04FD7BA7C}
hardpage.py wpstest time_%now%.csv pagefaults_%now%.csv _%now%
goto :exit
 
rem ---------------
:exit
echo "exit now..."
popd

预读处理

// FileOverlap.cpp : Defines the entry point for the console application.
//
 
#include "stdafx.h"
#include <Windows.h>
 
int cbCount = 0;
BOOL printfDetail = FALSE;
int loop_count = 200;
int successCount = 0;
int failedCount = 0;
 
#define COMPUTE_TIME(fun)  \
{ \
	DWORD begin = GetTickCount();\
	fun;\
	DWORD end = GetTickCount();\
	printf("\r\n %s: loopCount:%d - cbCount:%d - successCount:%d - timeUsed:%d", #fun, loop_count, cbCount, successCount, end - begin);\
}
 
 
void CALLBACK MyFileIOCompletionRoutine(DWORD dwErrorCode,  DWORD dwNumberOfBytesTransfered, LPOVERLAPPED lpOverlapped)
{
	if(printfDetail) {
		printf("\r\ndwErrorCode:%d - dwNumber:%d - offset:%d", dwErrorCode, dwNumberOfBytesTransfered, lpOverlapped->Offset);
	}	
	cbCount++;
	if(dwNumberOfBytesTransfered > 0) {
		successCount++;
	}
}
 
void useReadFileEx(LPCTSTR file) 
{
	HANDLE hFile = CreateFile(file, GENERIC_READ, 
		FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, NULL, OPEN_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN | FILE_FLAG_OVERLAPPED, NULL);
	if(hFile == INVALID_HANDLE_VALUE) {
		printf("bad file");
		return;
	}
 
	OVERLAPPED overlap = {0};
	const DWORD dwStepSize = static_cast<DWORD>(1024 * 1024 * 1);
	const DWORD dwReadSize = dwStepSize - 3072;
	LPVOID buffer = ::VirtualAlloc( NULL, dwStepSize, MEM_COMMIT, PAGE_READWRITE);	
	for(int i = 0; i < loop_count; i++)
	{
		overlap.Offset = (i % 1024) * dwStepSize;
		::ReadFileEx(hFile, buffer, dwReadSize, &overlap, MyFileIOCompletionRoutine);
	}
	if(printfDetail){
		printf("\r\nready wait.....");
	}
	while(loop_count >  cbCount){
		SleepEx(0, TRUE);
	}
	::VirtualFree(buffer, 0, MEM_RELEASE);
	::CloseHandle(hFile);
	if(printfDetail){
		printf("\r\nuseReadFileEx:cbCount:%d ", cbCount);
	}
}
 
void useReadFile(LPCTSTR file)
{
	HANDLE hFile = CreateFile(file, GENERIC_READ, 
		FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, NULL, OPEN_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN | FILE_FLAG_OVERLAPPED, NULL);
	if(hFile == INVALID_HANDLE_VALUE) {
		printf("bad file");
		return;
	}
	DWORD len = 0;
	OVERLAPPED overlap = {0};
	const DWORD dwStepSize = static_cast<DWORD>(1024 * 1024 * 1);
	const DWORD dwReadSize = dwStepSize - 3072;
	LPVOID buffer = ::VirtualAlloc( NULL, dwStepSize, MEM_COMMIT, PAGE_READWRITE);	
	for(int i = 0; i < loop_count; i++) {		
		overlap.Offset = (i % 1024) * dwStepSize;
		if(!::ReadFile(hFile, buffer, dwReadSize, &len, &overlap)) {
			if(GetLastError() == ERROR_IO_PENDING) {
				GetOverlappedResult(hFile, &overlap, &len, TRUE);
			}
		}
	}
	::VirtualFree(buffer, 0, MEM_RELEASE);
	::CloseHandle(hFile);
}
 
void useMoreReadFileEx(TCHAR (*files)[MAX_PATH], int count)
{
#if 1
	for(int i = 0; i < count; i++) {
		useReadFileEx(files[i]);
	}
#else
	OVERLAPPED overlap = {0};	
	const DWORD dwStepSize = static_cast<DWORD>(1024 * 1024 * 1);
	const DWORD dwReadSize = dwStepSize - 3072;
	LPVOID buffer = ::VirtualAlloc( NULL, dwStepSize, MEM_COMMIT, PAGE_READWRITE);	
	for(int j = 0; j < count; j++) {
		HANDLE hFile = CreateFile(files[j], GENERIC_READ, 
			FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, NULL, OPEN_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN | FILE_FLAG_OVERLAPPED, NULL);
		if(hFile == INVALID_HANDLE_VALUE) {
			printf("bad file");
			return;
		}
		for(int i = 0; i < loop_count; i++)
		{
			overlap.Offset = (i % 1024) * dwStepSize;
			::ReadFileEx(hFile, buffer, dwReadSize, &overlap, MyFileIOCompletionRoutine);
		}
	}
	SleepEx(0, TRUE);
#endif
}
 
void useMoreReadFile(TCHAR (*files)[MAX_PATH], int count)
{
	for(int i = 0; i < count; i++) {
		useReadFile(files[i]);
	}
}
 
int _tmain(int argc, _TCHAR* argv[])
{
	TCHAR path[MAX_PATH] = _T("c:\\package.zip");
	TCHAR files[10][MAX_PATH];
	int fileCount = 1;
	if(argc < 3) {
		printf("\r\nexample1: 1024 c:\1.zip");
		printf("\r\nexample1: 1024 c:\1.zip 1");
		printf("\r\nexample1: 1024 c:\1.zip 1 2");
		printf("\r\nexample2: 200 c:\cc|1.zip,2.zip");
		printf("\r\nexample2: 200 c:\cc|1.zip,2.zip 1");
		printf("\r\nexample2: 1024 c:\cc|1.zip,2.zip 1 2");
		return 0;
	}
	loop_count = _ttoi(argv[1]);
	_tcscpy(path, argv[2]);
	if(argc >= 3) {
		TCHAR *pmain = _tcstok(path, _T("|"));
		if(pmain != NULL) {
			TCHAR *pfile = _tcstok(NULL,  _T(","));
			int i = 0;
			for(i = 0; i < 10 && pfile != NULL; i++) {
				_stprintf(files[i], _T("%s\\%s"), pmain, pfile);
				pfile = _tcstok(NULL,  _T(","));
			}
			fileCount = i;
		}
	}
 
	if(argc > 3) {
		printfDetail = argc > 4;		
		if(fileCount > 1) {
			COMPUTE_TIME(useMoreReadFileEx(files, fileCount));
		}else{
			COMPUTE_TIME(useReadFileEx(path));
		}		
	}else if(argc == 3) {
		if(fileCount > 1) {
			COMPUTE_TIME(useMoreReadFile(files, fileCount));
		}else{
			COMPUTE_TIME(useReadFile(path));
		}
	}
	getchar();
	return 0;
}

cef的Qt的封装库及webrtc的测试

1.webrtc已经在cef3.x中支持。
2.由于cef的编译复杂性,有一些第三方机构专门编译一些全功能的二进制库,并提供了相应的例子,很方便地直接引入到第三方应用中。
3.在window中,简述其编译测试如下:
A-首先下载cef的库文件。下载地址如下:
http://opensource.spotify.com/cefbuilds/index.html【记住要下载32位的版本,不要下载64位的】
下载完成,先阅读其CMakeLists.txt文件,它说明了在各个平台该如何二次编译,如window的编译截图如下:

注:————–一定要用cmake -G “Visual Studio 14″【也即是vs2015,社区版就可以了编译了】的命令,令其生成工程vc的工程文件。———
注:————–不要用cmake的gui方式生成工程,因为可能会失败,而产生困扰——————————-
4.用vs2015打开工程,选择全编译。
5.调试cefclient工程,在调试器中添加–enable-media-stream选项。

6.打开webrtc的测试页面如下:
https://webrtc.github.io/samples/
7.截图如下:经验检,摄像头及声音都正常。


8.

—————————–
有人针对这场景写了一个QT的封装库,可以方便直接被Qt使用,在github随便搜索的结果有如下,可以逐个测试。
https://tishion.github.io/QCefView/
—————————
https://github.com/GreatTux/CefMinGWQt,这个是mingw版本。
———————————–
https://github.com/Dax89/QtCEF
——————-

带动态链接库的启动脚本

#!/bin/sh
 
path_current=`pwd`
path_script=$(cd "$(dirname "$0")"; pwd)
mode=$1
 
exe_name=NetSpeedServer
 
export PATH=$PATH:$path_script
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$path_script
 
app_process=`ps -ef | grep "$exe_name"| grep -v grep`
 
case "$mode" in
   'start')
        echo "it's ready to start op...."
        if test -n "$app_process"; then
                echo ""
                echo "$app_process"
                echo ""
        else
		cd $path_script
                nohup $path_script/$exe_name host=39.105.7.201 port=9513 > /dev/null 2>&1 &
		cd $path_current
 
        fi
 
        echo 'success to start.'
        ;;
   'stop')
        echo "it's ready to check process..."
        if test -n "$app_process"; then
                echo "had find app process informaton"
                echo $app_process | awk '{print ($2)}' | xargs kill -9
        fi
        echo 'success to kill.'
        ;;
    *)
        basename=`basename "$0"`
        echo "Usage: $basename  {start|stop}  [ server options ]"
        exit 1
        ;;
esac
exit 1

Apple相关离线下载

Apple相关的离线下载地址
https://developer.apple.com/downloads
虚拟机的苹果驱动,要解压把下面的iso文件提出来,直接安装。
http://softwareupdate.vmware.com/cds/vmw-desktop/fusion/8.5.8/5824040/packages/

Qt的国际语言怎么用

1.ts文件编写

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS>
<TS version="2.1" language="zh_CN" sourcelanguage="en">
<context> //可以有N多个上下文件,每个上下文就是一个类或一个QML文件
    <name>SystemTray</name>  //这个名字为类名,在工程里它只会翻译SystemTray类实例的相关文字。
    <message>
        <source>E&amp;xit</source>
        <translation>退出(&amp;x)</translation>
    </message>
    <message>
        <source>Hello World</source>
        <translation>世界,你好</translation>
    </message>
</context>
<context>
    <name>main</name>  //这个名字为main.qml的不带后缀名的文件名。
    <message>
        <source>E&amp;xit</source>
        <translation>退出(&amp;x)</translation>
    </message>
    <message>
        <source>Hello World</source>
        <translation>世界,你好</translation>
    </message>
</context>
</TS>

2.使用Qt语言家即Linguist程序,发布成qm文件。


3.代码启用

QString lang = QLocale::system().name();
    QTranslator translator;
    if (translator.load(":/res/i18n_zh.qm")) {
        QApplication::installTranslator(&translator);
    }