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. Test if WebAssembly in C++ code
Forum Updated to NodeBB v4.3 + New Features

Test if WebAssembly in C++ code

Scheduled Pinned Locked Moved Solved Qt for WebAssembly
4 Posts 3 Posters 1.1k Views 2 Watching
  • 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.
  • M Offline
    M Offline
    Mixlu
    wrote on last edited by Mixlu
    #1

    Hi,
    I have an application on Qt 5.13.2, I use MinGW (windows) for development and then I compile it in WebAssembly.
    I would like to call different C++ function depending on the compiler (mingw/webassembly), is there a way to do it in C++ files ?

    I have seen this but this is for the .pro file :

    contains(CONFIG, mingw) {
        
    } else {
        contains(CONFIG, wasm) {
           
        }
    }
    
    jsulmJ 1 Reply Last reply
    1
    • M Mixlu

      Hi,
      I have an application on Qt 5.13.2, I use MinGW (windows) for development and then I compile it in WebAssembly.
      I would like to call different C++ function depending on the compiler (mingw/webassembly), is there a way to do it in C++ files ?

      I have seen this but this is for the .pro file :

      contains(CONFIG, mingw) {
          
      } else {
          contains(CONFIG, wasm) {
             
          }
      }
      
      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by jsulm
      #2

      @Mixlu Such things are done via

      #ifdef SOMETHING
      // Do something
      #endif
      

      in C++ (https://en.cppreference.com/w/cpp/preprocessor/conditional).

      Such defines can be added using https://doc.qt.io/qt-5/qmake-variable-reference.html#defines in qmake:

      DEFINES += SOMETHING
      

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      M 1 Reply Last reply
      3
      • jsulmJ jsulm

        @Mixlu Such things are done via

        #ifdef SOMETHING
        // Do something
        #endif
        

        in C++ (https://en.cppreference.com/w/cpp/preprocessor/conditional).

        Such defines can be added using https://doc.qt.io/qt-5/qmake-variable-reference.html#defines in qmake:

        DEFINES += SOMETHING
        
        M Offline
        M Offline
        Mixlu
        wrote on last edited by
        #3

        @jsulm

        Thanks, this is what I was looking for!

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Hi,

          Even simpler use Qt's OS defines: Q_OS_WASM:

          #ifdef Q_OS_WASM
          // You WASM specific code
          #endif
          

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          6

          • Login

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