Win Registry

Question

One day, my boss want me to finish one function which let the users can double click project file(*.opr) to startup application easy and quickly. oh, This function is very common, Just like double clicked the Microsoft Word Document(*doc,*docx), then, we can startup Micrsoft Word Application to edit frich text. Ok, let's do it.

  1. Win And Mac OS use the different way to associated file type.
  2. Now the App only process one project at same time. if use the double click to open opr file. how to do when opend one project now?
  3. Current App mode is single-one mode.

How

When we get the new task about program, First to think about it. What's i will finish? Did i do it before? How i should to do ? If you think nothing, There is better way to get the answer from internet for you.

I think nothing. But, I know it is associate windows registry in Windows OS and List.Info file In Mac OS. So, I want to know how to finished it use the C++ or Qt. I also searched some documents about how to read/write registry with Qt. I was feel better that time. But when i tried all ways what them said, they are both failed. I spend half of the day, but not working. Their blogs not have the good introduction.

Now, I get the right answer from blogs of cnblogs.com. cnblogs.com is bester web site bout the programe than others.

Done

I used Qt frame to finished it. if you know QSettings classes, it will be very easy, if not, please to see thw Qt help manual about the QSettings class at first.

/** some include file */
#ifdef Q_OS_WIN
#include <QSettings>
#endif #ifdef Q_OS_WIN
void checkWinRegistry()
{
QString val;
QString exePath = qApp->applicationFilePath();
exePath.replace("/", "\\"); QSettings regType("HKEY_CURRENT_USER\\SOFTWARE\\Classes\\.abc",
QSettings::NativeFormat);
QSettings regIcon("HKEY_CURRENT_USER\\SOFTWARE\\Classes\\.abc\\DefaultIcon",
QSettings::NativeFormat);
QSettings regShell("HKEY_CURRENT_USER\\SOFTWARE\\Classes\\.abc\\Shell\\Open\\Command",
QSettings::NativeFormat); /** . means default value, you can also use the "Default" string */
if("" != regType.value(".").toString()){
regType.setValue(".","");
} /** 0 使用当前程序内置图标 */
val = exePath + ",0";
if(val != regIcon.value(".").toString()){
regIcon.setValue(".",val);
} val = exePath + " \"%1\"";
if(val != regShell.value(".").toString()){
regShell.setValue(".",val);
}
}
#endif int main(int argc, char *argv[])
{
QApplication a(argc, argv); checkWinRegistry(); /** if you want to get the file path, please use argv[1], if argc >= 2 */
QString text;
text = QString::number(argc);
text += "\n";
for(int i=0; i<argc; i++){
text += QString(argv[i]);///< This way to get the QString may be is unreadable code. eg, include chinese language, we should use `QStringList ltArguments = a.arguments();`
text += "\n";
} Widget w(text);
w.show(); return a.exec();
}

Compared

if you don't clear about my way. Now, you could to see the following images about How to associate file type in QtCreater. we know that double *.pro file, we can startup QtCreater application to programing. How ?

  1. In Windows we can use Ctrl+R and input regedit, Enter to open the windows registry editer.
  2. Let we find HKEY_CURRENT_USER\SOFTWARE\Classes\.pro, you can see what keys and values under this item;

  3. Then let we find HKEY_CURRENT_USER\SOFTWARE\Classes\QtProject.QtCreator.pro, what keys and values under this item;

  4. There are other file type of qt.

Compared and to finished your work by try and try.

Associate Aile Aype An Aac As

personal Blogs

qt.io

stackoverflow

Qt Mac Release

stackoverflow

qt.io

Info.plist Mac

stackoverflow:overriding Mac app file associations via CFBundleDocumentTypes in info.plist

Reference

wikipedia Windows Registry

support windows registry

wikipedia Registry cleaner

知乎:为什么Win要有注册表,而Unix其他系统不需要

win注册表详解

c# cnblogs

vc cnblogs

Qt Win wiki.qt.io

Qt Mac stackoverflow

Qt Mac csdn

Mac And Win csdn


Associate File Type with Qt In Mac Os and Win的更多相关文章

  1. QT在Mac OS上编译运行初体验

    QT是一个跨平台的框架,支持PC端(Windows.Linux和Mac OS)以及移动端(Android和IOS),之前的开发大都在Windows或者Ubuntu上,考虑到项目多平台支持性,本文对Ma ...

  2. Qt在Mac OS X下的编程环境搭建

    尊重作者,支持原创,如需转载,请附上原地址:http://blog.csdn.net/libaineu2004/article/details/46234079 在Mac OS X下使用Qt开发,需要 ...

  3. Qt在Mac OS X下的编程环境搭建(配置Qt库和编译器,有图,很清楚)

    尊重作者,支持原创,如需转载,请附上原地址:http://blog.csdn.net/libaineu2004/article/details/46234079 在Mac OS X下使用Qt开发,需要 ...

  4. vmware 安装 Mac OS X 10.9 Mavericks

    This guide shows how to install fresh OS X 10.9 Mavericks on VMware workstation with Windows 7 or Wi ...

  5. Qt在windows与Mac OS中获取执行程序版本号

    1 windows中获取执行文件exe的版本号   QString GetFileVertion(QString aFullName) { QString vRetVersion; string vF ...

  6. A MacFUSE-Based Process File System for Mac OS X

    referer: http://osxbook.com/book/bonus/chapter11/procfs/ Processes as Files The process file system  ...

  7. Mac OS X 10.10 Yosemite PHP 5.5.14 free type support fix

    通过将php将至5.4来勉强支持freetype扩展,不推荐此方法 after upgrading to new Mac OS X Yosemite, i noticed that free type ...

  8. 在 Virtual Box 安装 Mac Os 并安装 Qt 开发应用

    导读 由于 Beslyric-for-X 项目开发需要,开始尝试在 Mac Os 下开发 Qt 应用.尝试成功后,记录于此,希望对有类似需求的人有所帮助. 本文以开发 Beslyric-for-X 为 ...

  9. Mac OS安装octave出现的问题-'error:terminal type set to 'unknown'的解决'

    学习Machine learning需要使用Octave语言,毕竟Andrew Ng (恩达.吴)力荐.本机系统Mac OS X EI Capitan, 其实什么系统都无所谓了,安装原理都是一样的. ...

随机推荐

  1. Ubuntu下制作系统启动盘

    制作系统U盘: $ sudo umount /dev/sdc1 $ -desktop-amd64.iso of=/dev/sdc + records in + records out bytes (1 ...

  2. name_save matlab

    file=dir('/home/wang/Desktop/trainset/num0/');for i=3:length(file)     path= strcat('/home/wang/Desk ...

  3. Android GPS GPSBasics project hacking

    一.参考源码: GPS Basic Example - Android Example http://androidexample.com/GPS_Basic__-__Android_Example/ ...

  4. 每天一个linux命令(网络):【转载】route命令

    Linux系统的route命令用于显示和操作IP路由表(show / manipulate the IP routing table).要实现两个不同的子网之间的通信,需要一台连接两个网络的路由器,或 ...

  5. 关于cookie和session的使用和理解

    由于项目需要,最近用session容器比较多,传载的同时加上了自己的一些理解,不足之处还请大家补充和纠正. 一.cookie机制和session机制的区别 ********************** ...

  6. 高性能Mysql学习笔记之事务

    传送门 什么是事务? 事务就是一组原子性的SQL查询,或者说一个独立的工作单元.如果数据库引擎能够成功地对数据库应用该组查询的全部语句,那么就会执行该组查询.如果其中有任何一条语句因为崩溃或其他原因无 ...

  7. SqlServer高级特性--游标

    游标 用途:在数据很多的时候,如果在java代码中进行循环之后再进行更新数据,会造成频繁的连接数据库,耗费性能,所以就可以使用到游标 作用:查询出来的集合直接在SQL中进行遍历在进行更新 DECLAR ...

  8. 整理关于Java进行word文档的数据动态数据填充

    首先我们看下,别人整理的关于Java生成doc 的 资料. java生成word的几种方案 1. Jacob是Java-COM Bridge的缩写,它在Java与微软的COM组件之间构建一座桥梁.使用 ...

  9. Mac 使用ab性能测试工具

    Mac 使用ab命令进行压测 1.在Mac中配置Apache ①启动Apache,打开终端 sudo apachectl -v 如下显示Apache的版本 sudo apachectl start 这 ...

  10. 修改numa和io调度优化mysql性能

    一.NUMA设置单机单实例,建议关闭NUMA,关闭的方法有三种:1.硬件层,在BIOS中设置关闭:2.OS内核,启动时设置numa=off:3.可以用numactl命令将内存分配策略修改为interl ...