QDrag and Skype issue (win only) - c++

I am writing a little file/archives explorer and got an issue with interaction between qt-based app and Skype chat window on Windows platform only.
When I try to drag-drop file (provided by QDrag with file-urls mime data) from my app to skype chat window, file is sent twice. The same I’ve got when tried to modify one of Qt drag-drop examples.
Skype version is 5.10.0.116. Bug is reproducible on Qt versions 4.7.3, 4.8.1, 4.8.3.
EDIT:
Have tried drag-drop interactions between several apps
My app -> Explorer = ok
My app -> Notepad++ = ok (displays content of file only in one tab)
My app -> WinRar = ok (creates archive with
only one file)
My app -> TotalCommander = ok
My app -> ICQ = ok (only one file is sent)
My app -> Clementine (Qt based music player) = ok (only one file
is added to playlist)
Explorer -> Skype = ok
But
My app -> Skype - file is sent twice
Clementine -> Skype - file is sent twice
EDIT2:
Also, qt-created mime data differs from created by explorer.
Qt:
0 "text/uri-list" "file:///C:/Users/user/Pictures/myfile.ext"
1 "application/x-qt-windows-mime;value="UniformResourceLocatorW""
"..." (I've replaced QByteArray contents with ellipsis)
Explorer:
0 "application/x-qt-windows-mime;value="Shell IDList Array"" "..."
1 "application/x-qt-windows-mime;value="UsingDefaultDragImage""
"..."
2 "application/x-qt-windows-mime;value="DragImageBits"" "..."
3 "application/x-qt-windows-mime;value="DragContext"" "..."
4 "application/x-qt-windows-mime;value="DragSourceHelperFlags""
"..."
5 "application/x-qt-windows-mime;value="InShellDragLoop"" "..."
6 "text/uri-list" "file:///C:/Users/user/Pictures/myfile.ext"

I see, it’s not a problem if Qt, it’s wrong mime data processing on Skype side. Along with “text/uri-list”, Qt provides “UniformResourceLocatorW” value with the same data (i cant deny it, it is added a much deeper, than Qt user can get). And Skype processes both values – “text/uri-list” and “UniformResourceLocatorW”, causing sending the same file twice.

Related

c++ retrieve executable`s icon for use in windows registry icon path?

I am trying to set a value in windows registry of my application.
The executable path works fine by just adding the path but when i load it the icon of this application cannot be seen in windows programs.
How can i retrieve correctly the icon from my application and use it as icon path in the registry ?
Do i need to set something inside my application so the registry can see the icon ?
key reg for shell-open-command "C:\myapp\test.exe" "%1"
but for the key reg Default Icon "" do i need to use a regural .ico file near the exe or could i get also from the executable`s .exe file the ico i use from inside the application ?
I would like to avoid using .ico file so if it can be done by taking the executable`s file icon would be nice.
A good example to understand cause its not a duplicate is the torrent magnet links.
Check magnet->shell->open->command
and magnet->DefaultIcon
in system registry
Any help is much appreciated
The key value should be full path, followed by icon index.
For example DefaultIcon -> path.exe,-123 Here path.exe is expected to have an icon whose resource ID is 123
HKEY_CURRENT_USER\Software\Classes\.txt -> myapp
Create myapp and add subkey DefaultIcon
HKEY_CURRENT_USER\Software\Classes\myapp\DefaultIcon -> path.exe,-123
HKEY_CURRENT_USER\Software\Classes\myapp\shell\open\command -> "path.exe" /open "%1"

Dragging an image from Chrome to a Qt application

I am trying to get the data from an image dragged directly from a browser to my Qt app. I have the following code:
void MyView::dropEvent( QDropEvent* event )
{
QGraphicsView::dropEvent( event );
if ( event->mimeData()->hasImage() )
{
QImage image = qvariant_cast<QImage>( event->mimeData()->imageData() );
...
This works fine with Firefox (Windows/Mac), Safari (Mac) and IE (Windows). But QMimeData::hasUrl() returns false for Chrome on both Windows and Mac.
On further investigation Qt expects image data in MIME format "application/x-qt-image". It seems that Chrome doesn't provide this. Is there a workaround for Chrome? I haven't been able to find anything.

how to load qt compiled c++ code in maya?

Is there any way to load qt compiled c++ code in maya?
//example code
void MainWindow::on_pushButton_clicked()
{
ui->labell->setText("Hello");
}
actually i was created basic ui with text and push button, what i want is text should change to hello when i push button and i achieved that. so this connections were made with above code, after compiling this all works fine but when i load ui file in maya and i pushes the button text doesn't changes because actually code was written in c++. so, is there any alternative to load that code too along with ui file?
thank you,
Anvesh Chary
To load a .ui file in Maya, I've previously done this in python, I'm not sure about C++ but I don't believe maya interprets C++ directly anyway (I could be wrong there).
import maya.cmds as cmds
ve = cmds.about(version=True)
conv = "%s"%ve
versionOutput = float(conv[0:4])
def mayaVers():
cmds.warning("You're using Maya %s! You need to be using Maya 2011 or greater to be compatible with this script.\n" % conv);
def loadUIWindow():
if versionOutput >= 2011:
if (cmds.dockControl('dockUIWindow', exists=True)):
cmds.deleteUI('dockUIWindow')
scriptsDirectory = cmds.internalVar(usd=True)
UIWindow = cmds.loadUI(uiFile=scriptsDirectory + "/uifilename.ui")
dockSoftMod = cmds.dockControl('dockUIWindow',area="left", content='uiwindowname', label="")
else:
mayaVers()
loadUIWindow()
Here's how I've done it in the past, if you're just looking to source a UI file into the Maya session, this is how it can be done.
Obviously you'll need to either put your ui file in the scripts directory, or change the uiFilePath to your file.
Also, the content flag in the dockControl is important, this needs to be the name of the window or control that you're trying to dock. Let's say you have called your UI file wrapper 'win', the content flag would need to be the same.
EDIT
After you load the UI file, you can edit any element in the window if you know it's name.
cmds.button('ParentBtn', edit=1, command="parentObject()")
Hope this helps.

Programming with Qt creator and Cocoa ( copying the selected text from the current application)

I would like to know if there is a way to use the Cocoa API in a Qt application.
I've already used the Windows API to get the selected text from the active application.
I'd like to do the same with mac os.
I tried to make a simple "hello world" application C++ with xCode, including the <Cocoa/Cocoa.h> but it didn't work as I excepted.
Is there a way to get this "hello word" application to build with Cocoa?
And, also If that is possible, can I get the selected text from the active windows with Cocoa API?
EDIT :
All right, so I successfully build something using Cocoa.h, thanks to this thread : How to mix Qt, C++ and Obj-C/Cocoa.
For the selection problem you could check out the answers I posted which tell you how to do it.
For those who could be interested : I found a way to get the current selected text.
Just by simulating cmd + c :
So thanks to this thread, I changed the code to obtain the "c" key which is represented by the integer 8 (Found in NSEvent.h), so here's the code :
CGEventSourceRef source = CGEventSourceCreate(kCGEventSourceStateCombinedSessionState);
CGEventRef saveCommandDown = CGEventCreateKeyboardEvent(source, (CGKeyCode)8, YES);
CGEventSetFlags(saveCommandDown, kCGEventFlagMaskCommand);
CGEventRef saveCommandUp = CGEventCreateKeyboardEvent(source, (CGKeyCode)8, NO);
CGEventPost(kCGAnnotatedSessionEventTap, saveCommandDown);
CGEventPost(kCGAnnotatedSessionEventTap, saveCommandUp);
CFRelease(saveCommandUp);
CFRelease(saveCommandDown);
CFRelease(source);
Now you just have to access the clipboard from Qt to get the selection. (If ask, I can put the code to do so)
Anyway, thanks to the stackoverflow community ;)

How can I access the Apple Events "openFile" event in C++?

I'm interested in writing a small utility in C++ for Mac OS X to read, parse, save (over)write a file. I don't need any GUI, menus, or windows.
What type of project template do I need to start with in XCode?
How can I access the file that is passed in? (It's passed with Apple Events openFile, right?)
I've done a little C++ but nothing on Mac. Links appreciated, code samples appreciated more.
How do you intend to pass files to your application?
If it's via the command line then you would use the Command Line Tool template and access the command line parameters just as you would on any POSIX platform (argc and argv).
If you want to pass files to your application using Finder, say, by dropping files onto the application icon, then you would use the Cocoa Application template.
The Info.plist file contains your application configuration and supported document types, similar to the registry on Windows.
You configure Info.plist via the "Info" tab of your Project Settings (It's the top-most file in the file navigator in XCode). Click the "Add" button in the lower right, then select "Add Document Type" to add a document type that your application will accept. To accept all documents, set the document name to All and set the extension to *. More info is here.
Add a LSUIElement key in your Info.plist, and set its value to YES to indicate that your application has no UI. This key is also displayed as "Application is agent" in XCode. More info on LSUIElement is here.
In your MainMenu.xib, you can delete the Window and Font Manager objects that are there by default, since you won't be needing them.
Rename the AppDelegate.m file to AppDelegate.mm, so that it's compiled as Objective-C++. This will allow you to use C++ code in that file.
In the applicationDidFinishLaunching: delegate method, add [NSApp terminate:nil]; so that your app quits immediately when it's done its work.
Add the following method to AppDelegate.mm:
- (BOOL)application:(NSApplication*)app openFile:(NSString *)filename
{
NSLog(#"Opening file %#", filename);
char* cFilename = [filename UTF8String];
// Your C++ code goes here
return YES;
}
That's it. The rest is your C++ code. You can add any C++ code to AppDelegate.mm that you want. E.g.:
#include <string>
#include <iostream>
#include "MyCppFileProcessor.h"
- (BOOL)application:(NSApplication*)app openFile:(NSString *)filename
{
std::string cFilename([filename UTF8String]);
std::cout << "Processing file: " << cFilename << std::endl;
MyCppFileProcessor fileProcessor;
fileProcessor.processFile(cFilename);
return YES;
}
This code will run whenever you drop a document onto your Application's icon in Finder.
1)Use the Command Line Tool template. There are several options for this template. You may select C++ from the menu.
2)As far as I know IOstream will work just fine. Also, there's an argument parameter on your main() function, you may get the file name from these args.
http://www.cplusplus.com/reference/iostream/