Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for WebAssembly
  4. Is allow to use the QDrag class in Qt Webassembly?
QtWS25 Last Chance

Is allow to use the QDrag class in Qt Webassembly?

Scheduled Pinned Locked Moved Unsolved Qt for WebAssembly
qdragqt 6.5.1webassemblyqeventloopqthread
2 Posts 2 Posters 420 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Y Offline
    Y Offline
    Yash001
    wrote on last edited by
    #1

    Application is hang whenever it is reach to line drag->exec(Qt::CopyAction | Qt::MoveAction);

    It is work fine with mingw, msvc compiler.
    It is not work in brower.
    Using:
    Qt 6.5.1
    emsdk 3.1.25

    #include "ElementDragEventHandler.h"
    
    #include "AbstractElement.h"
    
    #include <qevent.h>
    #include <qlabel.h>
    #include <qdrag.h>
    #include <qmimedata.h>
    
    
    
    bool ElementDragEventHandler::eventFilter(QObject* watched, QEvent* event)
    {
    
        if (event->type() == QEvent::MouseButtonPress) {
    
            QWidget* label = qobject_cast<QWidget*>(watched);
            if (label && label->property("element").isValid()) {
    
                // Get the element data stored in the label
                AbstractElement* element = qvariant_cast<AbstractElement*>(label->property("element"));
    
                // Create a drag object
                QDrag* drag = new QDrag(label);
                QMimeData* mimeData = new QMimeData;
    
                // Set the element as the mime data
                mimeData->setProperty("element", QVariant::fromValue(element));
    
                drag->setMimeData(mimeData);
    
                // Set the drag pixmap
                QPixmap pixmap = element->getImage().scaled(90, 90); // Adjust the size as needed
                drag->setPixmap(pixmap);
    
    
                // Start the drag
                drag->exec(Qt::CopyAction | Qt::MoveAction);
                return true;
            }
        }
    
        return QObject::eventFilter(watched, event);
    }
    
    

    anything I need to change.

    # Define the project name and version
    TEMPLATE = app
    TARGET = myApp
    VERSION = 0.1.0
    
    # Define the target platform and architecture
    QMAKE_TARGET.arch = wasm
    
    # Set the C++ version and compiler flags
    CONFIG += c++17
    QMAKE_CXXFLAGS += -std=c++17
    
    # Enable precompiled headers
    #PRECOMPILED_HEADER = $$PWD/src/pch.h
    
    # Define the source files
    SOURCES += $$PWD/src/main.cpp ......
               
    
    # Define the header files
    HEADERS += $$PWD/src/MainWindow.h ....
              
    
    # Define the resource files
    RESOURCES += $$PWD/src/resources.qrc
    
    # Include the required Qt modules
    QT += core gui widgets
    
    # WebAssembly-specific settings
    wasm {
        # Set the output directory for WebAssembly build
        DESTDIR = $$PWD/build-wasm
    
        # Enable WebAssembly support
        CONFIG += wasm
    
        # Include the Emscripten libraries
        INCLUDEPATH += $$PWD/3rdParty/emsdk/upstream/emscripten/system/include
        LIBS += -L $$PWD/emsdk/upstream/emscripten/system/lib \
                -lglut -lGLU -lGL
    
        # Set the deployment directory for WebAssembly build
        QMAKE_PREFIX_PATH += $$PWD/build-wasm/qtbase
    
        # Link against the Emscripten libraries
        LIBS += -s USE_GLFW=3 -s WASM=1 -s USE_WEBGL2=1 -s PTHREAD_POOL_SIZE=100
    
        # Add WebAssembly-specific compiler flags
        QMAKE_CXXFLAGS += -s FORCE_FILESYSTEM=1
    }
    
    # Link against the Qt libraries
    LIBS += -L "C:/Qt6/6.5.1/wasm_multithread/lib/libQt6Core.a" -L "C:/Qt6/6.5.1/wasm_multithread/lib/libQt6Gui.a" -L "C:/Qt6/6.5.1/wasm_multithread/lib/libQt6Widgets.a"
    
    
    1 Reply Last reply
    0
    • lorn.potterL Offline
      lorn.potterL Offline
      lorn.potter
      wrote on last edited by
      #2

      Drag and drop has never worked very well in QtWebAssembly.
      But it is working in 6.6.0beta1 single threaded release.

      You need to use asyncify though:
      https://doc.qt.io/qt-6/wasm.html#asyncify

      Good news is, you no longer have to rebuild Qt to get asyncify, you just need to add a linker argument.
      cmake: target_link_options(<target> PUBLIC -sASYNCIFY -Os)
      qmake: QMAKE_LFLAGS += -sASYNCIFY -Os

      Freelance Software Engineer, Platform Maintainer QtWebAssembly, Maintainer QtSensors
      Author, Hands-On Mobile and Embedded Development with Qt 5 http://bit.ly/HandsOnMobileEmbedded

      1 Reply Last reply
      2

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved