Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Unsolved Is allow to use the QDrag class in Qt Webassembly?

    Qt for WebAssembly
    qdrag qt 6.5.1 webassembly qeventloop qthread
    2
    2
    83
    Loading More Posts
    • 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
      Yash001 last edited by

      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 Reply Quote 0
      • lorn.potter
        lorn.potter last edited by

        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 Reply Quote 2
        • First post
          Last post