[SOLVED][Drag'n Drop] QMainWindow and linking error



  • Hi everybody !

    I'm new to Qt, and I'm a little, very little confused with the Qt-Classes tree.

    I wrote an app, which will crypt (with QCA) the dragged desktop files, dropped in my app (opened).
    The thing is my main "window" is a QMainWindow inherited by my custom class.

    I know that CustomClass -> QMainWindow -> QWidget, so the drag'n drop features should work directely on my class, isn't it? (according to: "F.A.Q":http://developer.qt.nokia.com/faq/answer/how_can_i_do_drag_and_drop_in_a_widget)

    But, when I add the protected definitions in my class Custom {}, it fails compilling:
    @Undefined symbols:
    "MainWindow::dragMoveEvent(QDragMoveEvent*)", referenced from:
    vtable for MainWindowin moc_mainwindow.o
    "MainWindow::dragEnterEvent(QDragEnterEvent*)", referenced from:
    vtable for MainWindowin moc_mainwindow.o
    "MainWindow::makeDrag()", referenced from:
    MainWindow::qt_metacall(QMetaObject::Call, int, void**)in moc_mainwindow.o
    "MainWindow::dropEvent(QDropEvent*)", referenced from:
    vtable for MainWindowin moc_mainwindow.o
    ld: symbol(s) not found@

    Any Idea :/ ?
    And... At least, is it supposed to work T_T ?

    PS: Here is my .h: http://pastebin.com/MgMH2GKX

    Thanks for you help.



  • Hi Max13,

    can you please also show your cpp file?
    I think you perhaps have forgotten the implementation?



  • Hi,
    I've let the implementation away, I was testing.
    Because I've noticed that GCC can complain about missing definition, but not for missing implementation.

    Isn't it? =P



  • You must at least have empty functions.
    They needn't be filled but the function body is a must.



  • Ok, I'll do it.
    BTW, do you know if the implementation explained in the FAQ, if I Want to be able to drag-n-drop from the desktop to my app? (since it's not a part of my app =/ )

    ?
    Thanks for tour help!



  • Hi,

    I did that once and could dig a bit for it, but that takes time.
    In general, you have to do it like in the docs, I never used this faq, only the online docs.

    You can start at the "examples for drag'n'drop":http://doc.qt.nokia.com/4.7/examples-draganddrop.html



  • Hi,

    I created a small wiki article on how to open files from drag operations inside a QMainWindow:

    "wiki article":http://developer.qt.nokia.com/wiki/Drag_and_Drop_of_files

    On windows, I would connect that with the "assignment of file types":http://developer.qt.nokia.com/wiki/Assigning_a_file_type_to_an_Application_on_Windows

    Hope that helps a bit.

    Have fun.



  • Hi,

    Thank you a lot !
    I've added empty functions, and it worked (:/).

    Thank, I saw your Wiki, GREAT !
    But something wrong (perhaps from me, perhaps from Qt)

    @void MainWindow::dropEvent(QDropEvent *de)
    {
    const QMimeData * mimeData = de->mimeData();

    if (mimeData->hasUrls())
    {
    qDebug() << mimeData->urls(); // Line 10
    }
    }@

    I have tons of errors :/
    Line 10 above is line 10 here: http://pastebin.com/89k8G0aq

    Thank you for your help anyway :)



  • Hi Max,

    I'm not sure, whether QList<QUrls> is able to be streamed to qDebug.
    If you read the wiki, you will find I use the local paths of the urls, so like this:

    @
    void DocumentWindow::dropEvent(QDropEvent* event)
    {
    const QMimeData* mimeData = event->mimeData();

    // check for our needed mime type, here a file or a list of files
    if (mimeData->hasUrls())
    {
        QList<QUrl> urlList = mimeData->urls();
    
        // extract the local paths of the files
        for (int i = 0; i < urlList.size() && i < 32; ++i)
        {
            qDebug() << urlList.at(i).toLocalFile&#40;&#41;;
        }
    }
    

    }
    @



  • Sorry...

    Usually, i'm less dumb ^^

    I have the same errors with this line: @QList<QUrl> urlList = mimeData->urls();@

    So:
    @void MainWindow::dropEvent(QDropEvent *de)
    {
    const QMimeData * mimeData = de->mimeData();

    if (mimeData->hasUrls())
    {
    QList<QUrl> urlList = mimeData->urls();
    }
    }@

    Is the error between my chair and my computer ? =P



  • [quote author="Max13" date="1302617263"]Is the error between my chair and my computer ? =P[/quote]

    Perhaps :-)

    I saw you are using Qt 4.7.3?
    I only tried with 4.7.2... on windows
    There I had no problems.

    Are you missing some includes? The error talks about forward declarations...

    @
    #include <QtCore/QUrl>
    #include <QtCore/QList>

    @



  • Hi !
    Sorry for having made the dead.

    I've reinstalled the libs, did everything you explained, and...

    IT WORKS GREAT !!

    Thank you a lot for you patience.
    I'm done now :)


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.