Navigation

    Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Search
    1. Home
    2. Tags
    3. function
    Log in to post

    • UNSOLVED How does Qt call C++ functions from JavaScript through webassembly?
      Qt for WebAssembly • javascript function webassembly export • • AliGB  

      3
      0
      Votes
      3
      Posts
      82
      Views

      It is possible to call c/c++ functions from javascript as well as call javascript from c/c++. Look at https://emscripten.org/docs/porting/connecting_cpp_and_javascript/Interacting-with-code.html
    • UNSOLVED Calling C++ function from JavaScript through Webassembly
      Qt for WebAssembly • javascript function webassembly wasm export • • AliGB  

      2
      0
      Votes
      2
      Posts
      70
      Views

      You need to export those by adding linker arguments: https://emscripten.org/docs/porting/connecting_cpp_and_javascript/Interacting-with-code.html#interacting-with-code-ccall-cwrap
    • SOLVED Final task upon program termination
      QML and Qt Quick • qml c++ qt5 signal & slot function • • texasRanger  

      3
      0
      Votes
      3
      Posts
      68
      Views

      @fcarney Sweet! That worked, thanks.
    • UNSOLVED QML proper using nested functions
      QML and Qt Quick • qml button style function nested • • Kyeiv  

      2
      0
      Votes
      2
      Posts
      82
      Views

      Hi @Kyeiv, I just did a quick test application and it worked for me: main.qml import QtQuick 2.9 import QtQuick.Window 2.2 import "someJSscriptFile.js" as Jss Window { visible: true width: 640 height: 480 title: qsTr("Hello World") Rectangle { id: rect color: Jss.getCurrentColor() anchors.fill: parent } } someJSScriptFile.js function getCurrentColor() { return __getColor(rect.currentValue) } function __getColor(value) { if (rect.pressed) { return "grey" } if(rect.activated === false) { return "white" } if(value ===0) { return "red"; } return "green"; } Is the variable "control" defined in your QML? Or what are you trying to use it for?
    • SOLVED GUI Freezes When Loop is Started
      QML and Qt Quick • qml thread function loop qml dynamic • • closx  

      7
      0
      Votes
      7
      Posts
      199
      Views

      @jsulm U are da king! I am dealing with QML for months, and just learning the property variables! That kinda saved my life mate! Thank you very much!
    • SOLVED How to restart an application by pressing a button?
      QML and Qt Quick • qml qtcreator qtquick function restart • • closx  

      10
      0
      Votes
      10
      Posts
      1892
      Views

      @J.Hilk Hey, Thank you for all of your help. Solved the problem thanks to you! If there is anyone facing the same issue, solved like this, Created a source file named "restarter" restarter.h #ifndef RESTARTER_H #define RESTARTER_H #include <QObject> class Restarter : public QObject { Q_OBJECT public: explicit Restarter(QObject *parent = nullptr); Q_INVOKABLE void makeRestart(); signals: public slots: }; #endif // RESTARTER_H restarter.cpp (note: my application works as a service named "myservice" on system, so I can not restart it as restarting a regular application.) #include "restarter.h" #include <QProcess> Restarter::Restarter(QObject *parent) : QObject (parent) { } void Restarter::makeRestart() { QProcess::execute("sudo service myservice restart"); } If your application works NOT AS A SERVICE, BUT AN APPLICATION, restarter.cpp #include "restarter.h" #include <QApplication> #include <QProcess> Restarter::Restarter(QObject *parent) : QObject (parent) { } void Restarter::makeRestart() { qApp->quit(); QProcess::startDetached(qApp->arguments()[0], qApp->arguments()); //application restart } You need to register "restarter.cpp" as a QML registery (I know, stupid sentence) So you need to insert these lines in main.cpp #include "restarter.h" qmlRegisterType<Restarter>("closx.restarter", 1, 0, "Restarter"); and use it on your QML file: import closx.restarter 1.0 Restarter { id:restarter } Rectangle{ id: restartbg width: 120 height: 70 radius: 8 color:"black" anchors.centerIn: parent z:344 Text{ anchors.centerIn: parent text:qsTr("Restart") + mytrans.emptyString font.family:GSystem.myriadproita.name font.pixelSize: 18 color: "white" } MouseArea{ anchors.fill: parent onClicked: { restarter.makeRestart() } onPressed: { restartbg.color = "#1c1c1c" } onReleased: { restartbg.color = "black" } } } Again, thanks to @LeLev and @J-Hilk for everything.
    • SOLVED Access function/slot loader element in listview
      QML and Qt Quick • listview loader function • • Delta_sim  

      4
      0
      Votes
      4
      Posts
      301
      Views

      Indeed it works ! I did 2 mistakes, I forgot ".item" after currentItem and I didn't changed currentIndex when I switch between pages because I use positionViewAtIndex. But positionViewAtIndex don't change currentIndex of the listView. Thanks guys !
    • SOLVED public function to set lineedit in mainwindow
      General and Desktop • embedded linux function public lineedit • • TMJJ001  

      28
      0
      Votes
      28
      Posts
      2141
      Views

      @Pablo-J.-Rogina Thanks for the time to make example code. It didn't work straight away, this because I use qt4.8 and you the newer one probably. So I changed your code to the older syntax to get it working. I would like to thank you and all others for there help! Again I learned a lot! Thanks for helping!
    • SOLVED Convert strings in a label to a function
      General and Desktop • function string • • WuliTiger  

      16
      0
      Votes
      16
      Posts
      3284
      Views

      If you guys are still interested in the topic. See https://github.com/chalkwu/control-system. I think it is a basic DIY solution. Cheers.
    • SOLVED Function after setupUi()
      General and Desktop • function show setup • • t0msk  

      31
      0
      Votes
      31
      Posts
      10499
      Views

      @kshegunov said in Function after setupUi(): Probably flooding the main thread's event loop. Okey I optimized a code little bit: QtConcurrent::run([=]() { int i; int value; double dResult = 1; for(i = 0;i < 20000000;i++) { dResult = qExp(qCos(qTan(qSin(qPow(qSqrt(((((i * 1337) / 7) * 73) * 1329) % 1937),7) * dResult)) / qAsin(qPow(qSin(dResult * i * qTan(1337 * i)), 29)))); if((i % 200000) == 0) { value = i / 200000; emit showResult(QString::number(dResult)); emit pBarSetValue(value); } } emit showResult(QString::number(dResult)); emit pBarSetValue(100); }); It tooks few seconds for my CPU, but yea UI is responsible and progressbar is changing in realtime Problem was because emit showResult(QString::number(dResult)); emit pBarSetValue(i); runs 5000000 times I don't follow. Add a stop signal where? You run a function imperatively with the proposed QtConcurent::run (as C++ is an imperative language), you can't just break in the middle of it ... I dont know, maybe that Quit Application signal will tell to OS scheduler that scheduler has to kill worker thread So only disadvantage of that method is that I cannot stop worker thread in middle of operation? //EDIT, thanks for help :)
    • SOLVED How to call an object created in another function.
      General and Desktop • c++ function • • ronyNS  

      17
      0
      Votes
      17
      Posts
      2995
      Views

      @ronyNS said: lbl = new Qlabel(); misspelled ? its QLabel ? lbl = new QLabel(); big L ?
    • UNSOLVED How to pass a function as model data?
      QML and Qt Quick • qml model function modeldata role • • jdcordoba  

      4
      0
      Votes
      4
      Posts
      1273
      Views

      That's a brilliant and elegant solution! Thank you bro for spending your precious time with a newbie like me!
    • SOLVED Problem with saving function (overwrite file which saved by dialog)
      General and Desktop • qtextedit file function save • • HenrikSt.  

      25
      0
      Votes
      25
      Posts
      6802
      Views

      The cause for that crash can be everything! How should anybody know what it is without your code? Did you try to debug your program to see where it crashes?
    • SOLVED How do I access the children of a repeater object in a function?
      QML and Qt Quick • qml javascript function repeater children • • dxmachina  

      5
      1
      Votes
      5
      Posts
      5848
      Views

      @dxmachina Well, that's not true ;) Just a little mistake. Happy coding! :D
    • SOLVED Function with Signals & Slots
      General and Desktop • signal & slot function • • gabor53  

      38
      0
      Votes
      38
      Posts
      7328
      Views

      Thank you all. It worked.
    • SOLVED newFunction in QJSEngine missing
      General and Desktop • function qjsengine • • walteste  

      9
      1
      Votes
      9
      Posts
      3680
      Views

      @zerocom I had the same issue and your comment helped me to solve it. but this solution seems to be working for predefined number of arguments for invokable functions. is there any way to create an invokable function with variable argument number similar to what we used to do by QScriptContext?
    • UNSOLVED why qml can't read the function
      General and Desktop • qml function • • Eman  

      2
      0
      Votes
      2
      Posts
      644
      Views

      Hi, Please explain exactly what is the problem
    • Record a specific value from databse
      QML and Qt Quick • sql database sqlite function property sqlite database • • Pisko  

      1
      0
      Votes
      1
      Posts
      687
      Views

      No one has replied

    • [Solved] Running function with QtConcurrent::run
      Mobile and Embedded • thread function run concurrent • • McLion  

      9
      0
      Votes
      9
      Posts
      8476
      Views

      I'd like to add: Specially if the Watcher needs to be used multiple times it's important to disconnect it after use: disconnect(FormatWatcher, SIGNAL(finished()), this, SLOT(FinishedFormat())); // disconnect former slot used with watcher
    • [Solved]Call function in script
      General and Desktop • qt5.5 signal & slot javascript function qjsengine script qjsvalue • • TheHawk  

      2
      0
      Votes
      2
      Posts
      1712
      Views

      I managed using the following additional lines in CustomCode QString function = "test(1)"; QJSValue testfunction = myEngine.evaluate(function); qDebug() << testfunction.toString(); With my script CustomLogic.qs looking like this: function test(x) { var a = "tested!"; a = a + x.toString(); return a; } Returns "tested!1" in the application output
    • can create a user-defined signals static?Or Changing the value of a variable to make sure that the function?
      General and Desktop • function signals emit change valuechanged • • ForestPoem  

      9
      0
      Votes
      9
      Posts
      1837
      Views

      @ForestPoem In the slot you know which signal was emitted (the one you connected it to), you can even get the pointer to the object which emitted the signal using sender()
    • QPixmap path
      General and Desktop • qpixmap file function path get • • reina  

      3
      0
      Votes
      3
      Posts
      2946
      Views

      @reina Could you provide us with a usecase? In my experience, a QPixmap only interacts with file storage at initialization and is then a blob of data with an API for internal use.
    • [SOLVED] Qt signals
      General and Desktop • signal & slot signal function definition • • Lorence  

      4
      0
      Votes
      4
      Posts
      1275
      Views

      It's important not to get distracted by the details. The gist of it is simple. Sorta action-reaction setup. One object emits a parametrized signal and any number of connected objects get a slot invoked with the signal parameter passed.
    • [SOLVED]function returning QSQLQueryModel
      General and Desktop • function qsqlquerymodel • • cpuin  

      6
      0
      Votes
      6
      Posts
      2003
      Views

      You have more information about why you can't copy QObject derived class here
    • Accessing methods of a lib
      General and Desktop • function qtplugin • • brcontainer  

      3
      0
      Votes
      3
      Posts
      833
      Views

      @dheerendra said: You need to get a instance to QObject and type cast to required interface. From plugin? The QT automatically loads the plugin (qtdir/plugins/webkit/qwebkitplatformplugin.dll), do not know if it is used QPluginLoader, I noticed that if I add qdebug() << "test"; in dll it shows in the main console application, maybe I can use QApplication to share "data".