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.

  1. /** some include file */
  2. #ifdef Q_OS_WIN
  3. #include <QSettings>
  4. #endif
  5. #ifdef Q_OS_WIN
  6. void checkWinRegistry()
  7. {
  8. QString val;
  9. QString exePath = qApp->applicationFilePath();
  10. exePath.replace("/", "\\");
  11. QSettings regType("HKEY_CURRENT_USER\\SOFTWARE\\Classes\\.abc",
  12. QSettings::NativeFormat);
  13. QSettings regIcon("HKEY_CURRENT_USER\\SOFTWARE\\Classes\\.abc\\DefaultIcon",
  14. QSettings::NativeFormat);
  15. QSettings regShell("HKEY_CURRENT_USER\\SOFTWARE\\Classes\\.abc\\Shell\\Open\\Command",
  16. QSettings::NativeFormat);
  17. /** . means default value, you can also use the "Default" string */
  18. if("" != regType.value(".").toString()){
  19. regType.setValue(".","");
  20. }
  21. /** 0 使用当前程序内置图标 */
  22. val = exePath + ",0";
  23. if(val != regIcon.value(".").toString()){
  24. regIcon.setValue(".",val);
  25. }
  26. val = exePath + " \"%1\"";
  27. if(val != regShell.value(".").toString()){
  28. regShell.setValue(".",val);
  29. }
  30. }
  31. #endif
  32. int main(int argc, char *argv[])
  33. {
  34. QApplication a(argc, argv);
  35. checkWinRegistry();
  36. /** if you want to get the file path, please use argv[1], if argc >= 2 */
  37. QString text;
  38. text = QString::number(argc);
  39. text += "\n";
  40. for(int i=0; i<argc; i++){
  41. 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();`
  42. text += "\n";
  43. }
  44. Widget w(text);
  45. w.show();
  46. return a.exec();
  47. }

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. Yii Model

    REFs 自动生成代码 创建第一个Yii应用 创建模型 Yii 用户登陆机制

  2. python中多线程

    多线程 什么是多线程 开启线程的两种方式 进程和线程的区别 Thread对象的其他属性和方法 守护线程 死锁现象与递归锁 信号量.Event定时器 线程Queue 进程池和线程池 什么是多线程 在传统 ...

  3. ZetCode PyQt4 tutorial widgets II

    #!/usr/bin/python # -*- coding: utf-8 -*- """ ZetCode PyQt4 tutorial In this example, ...

  4. .net core microservices 架构之 分布式

    .net core microservices 架构之 分布式  一:简介   自动计算都是常驻内存的,没有人机交互.我们经常用到的就是console job和sql job了.sqljob有自己的宿 ...

  5. Dijkstra算法(C语言)

    Dijkstra算法 1.定义概览 Dijkstra(迪杰斯特拉)算法是典型的单源最短路径算法,用于计算一个节点到其他所有节点的最短路径.主要特点是以起始点为中心向外层层扩展,直到扩展到终点为止.Di ...

  6. Windows 7 x64 安装 Oracle 11g Express

    1. 下载    在这里下载文件: Oracle Database Express Edition 11g Release 2 for Windows x32    Oracle 不提供 window ...

  7. oracle 查版本号

    oracle是强大的数据库,我们怎样看它的版本呢? 工具/原料 oracle 数据库, sqlplus 方法/步骤 首先进入sqlplus,cmd---plsql,登陆我们的用户,如:user/pas ...

  8. cocos2dx 3.0 +VS2013 环境搭建

    1.需要javasdk,android sdk,ndk,python 2.各种环境变量配置如下: JAVA_HOME:C:\Program Files\Java\jdk1.7.0_67 Path:%J ...

  9. cocos2dx 安卓真机调试问题汇总

    cocos compile编译apk问题汇总: 1,dx编译报错,没有足够的空间 ANTBUILD : [dx] error : Could not create the Java Virtual M ...

  10. return 0;和exit(0);的区别

    首先说一下fork和vfork的差别: fork 是 创建一个子进程,并把父进程的内存数据copy到子进程中. vfork是 创建一个子进程,并和父进程的内存数据share一起用. 这两个的差别是,一 ...