PDA

View Full Version : Drag incomming localurl !=linux not work kde



patrik08
26th November 2006, 12:33
If i drag on my widged a local file in to qtextedit on mac & window the file is open
but on linux kde no ... Why?

result display ....
file:///home/username/Desktop/mone.xml
and not display file inside xml??

kubuntu 6.0.6 uname 2.6.15





void Gui_Main::dragEnterEvent(QDragEnterEvent *event)
{
qDebug() << "### mousePressEvent " ;
event->acceptProposedAction();
}
void Gui_Main::dropEvent(QDropEvent *event)
{
if(event && event->mimeData()) {
Grabdata(event->mimeData());
}
}
void Gui_Main::Grabdata(const QMimeData *data)
{
if (!data) {
return;
}
QList<QUrl> urlelist;
if (data->hasUrls()) {
urlelist = data->urls();
for ( int i = 0; i < urlelist.size(); ++i ) {
QString unfilone = urlelist.at(i).toLocalFile();
qDebug() << "### url " << unfilone;
if (is_file(unfilone)) {
if (unfilone.endsWith(".fo")) {
OpenOtherResult(unfilone);
} else if (unfilone.endsWith(".xml")) {
LoadXmlFile(unfilone);
} else if (unfilone.endsWith(".xsl")) {
LoadXsltFile(unfilone);
}
}
}
}
}


all code on http://visual-xsltproc.svn.sourceforge.net/viewvc/visual-xsltproc/Visual_XSLTPro_Debug_qt4.2/

wysota
9th December 2006, 12:06
Could you post a minimal compilable example which reproduces the problem?

patrik08
9th December 2006, 20:07
I attach file...
here ist the small drag in url to qtextedit ...
and a.arguments() that fail on mac on main && drag in on kde (only kde)

you can self use the apps to read this 3 file

main.cpp
openmyfile.cpp
openmyfile.h
drag_test.pro

qmake && make & find apps on ....



TARGET = dragfile
win32 {
DESTDIR += ./
}
unix {
DESTDIR += ~/Desktop
}
mac {
DESTDIR += /Applications
}

wysota
9th December 2006, 23:46
Is it really a minimal compilable example?

So what is the incorrect behaviour? It seems to work correctly for me (KDE 3.5.4) I drag the file onto the label, drop it and its contents appear in the text box below.

BTW. Placing files on peoples' desktops is not something I'd call "nice". Please try to avoid it next time when posting an example.

patrik08
11th December 2006, 14:24
Is it really a minimal compilable example?

So what is the incorrect behaviour? It seems to work correctly for me (KDE 3.5.4) I drag the file onto the label, drop it and its contents appear in the text box below.

BTW. Placing files on peoples' desktops is not something I'd call "nice". Please try to avoid it next time when posting an example.


on my KDE not running ... kubuntu qt4.1 packace from debs url

it display inside qtextedit "file:///path/blabla.xx"... as text not read inside

i suppose toLocalFile(); is os different....




void OpenMyFile::Grabdata(const QMimeData *data)
{
if (!data) {
return;
}
QList<QUrl> urlelist;
if (data->hasUrls()) {
urlelist = data->urls();
for ( int i = 0; i < urlelist.size(); ++i ) {
QString unfilone = urlelist.at(i).toLocalFile();
/////qDebug() << "### url " << unfilone;
QFile f(unfilone);
if (f.exists()) {
OpenFile(unfilone);
}

}
}
}

wysota
11th December 2006, 14:30
it display inside qtextedit "file:///path/blabla.xx"... as text not read inside
You're dropping on a wrong widget. The text edit has its own drop handler which is displaying text carried by the drag and it happens that URLs are stored as text, so it's a perfectly good drag for the text edit, so it handles the event and doesn't pass it to a parent widget where your drop handler resides. Try dropping outside the text edit.


i suppose toLocalFile(); is os different....
Of course it's os specific, but toLocalFile() doesn't have anything to do here - it's not even called when you drop on the text edit.

sunil.thaha
11th December 2006, 15:23
You're dropping on a wrong widget. The text edit has its own drop handler which is displaying text carried by the drag and it happens that URLs are stored as text, so it's a perfectly good drag for the text edit, so it handles the event and doesn't pass it to a parent widget where your drop handler resides. Try dropping outside the text edit.


Or from the C++ Gui programming Book

Suppose the QTextEdit is inside a main Window then


MainWindow::MainWindow( ... ){
[...]
textEdit->setAcceptDrops( false );
setAcceptDrops( true );
}

void MainWindow::dragEnterEvent( QDragEnterEvent *e ) {
// accept if you can decode the mime data
}

void MainWindow::dropEvent( QDropEvent *e ) {
// get the file from the mime Data
readFile( file );
}