Results 1 to 4 of 4

Thread: QMl lost parameter when call a c++ function

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Aug 2013
    Posts
    27
    Thanks
    3

    Unhappy QMl lost parameter when call a c++ function

    There's a problem when I call C++ function in QML. I already upload souce code in attach file.
    In my project, i export a class to QML in main function.
    Qt Code:
    1. int main(int argc, char *argv[])
    2. {
    3. QGuiApplication app(argc, argv);
    4. qRegisterMetaType<ProgramParam>("ProgramParam");
    5. qRegisterMetaType<ProgramParamList>("ProgramParamList");
    6. qmlRegisterType<ProgramParam>("ProgramParam",1,0,"ProgramParam");
    7. qmlRegisterType<ConnectionBridge>("ConnectionBridge",1,0,"ConnectionBridge");
    8. QQmlApplicationEngine engine;
    9. engine.load(QUrl(QStringLiteral("qrc:///main.qml")));
    10.  
    11. return app.exec();
    12. }
    To copy to clipboard, switch view to plain text mode 
    In ConnectionBridg class, I export a function to append param to paramList
    Qt Code:
    1. Q_INVOKABLE void appendParam(ProgramParam p);
    2.  
    3. void ConnectionBridge::appendParam(ProgramParam p)
    4. {
    5. qDebug() << "ConnectionBridge::appendParam p.size :" << p.m_addrList.size();
    6. m_programParamList.append(p);
    7. }
    8.  
    9. void ProgramParamList::append(ProgramParam &p)
    10. {
    11. qDebug() << "ProgramParamList::append p.size :" << p.m_addrList.size();
    12.  
    13. m_programParamList.append(p);
    14. }
    To copy to clipboard, switch view to plain text mode 

    And what I want to do is when "program " button clicked, QML can prepare several ProgramParam object, and append it to m_programParamList. You can find it in main.qml, line 755 to line 776.
    Qt Code:
    1. var programConfig = prepareOneTypeProgramConfig(i);
    2. if(!programConfig.isEmpty())
    3. {
    4. // console.log("add to myltyProgramParam!");
    5. // programConfig.print();
    6. var aProgramParam = Qt.createQmlObject('import ProgramParam 1.0; ProgramParam {}', buttonProgram, "dynamicSnippet1");
    7.  
    8. aProgramParam.addrList = programConfig.addrList;
    9. console.log("update addressList");
    10. aProgramParam.controlerType = programConfig.controlerType;
    11. aProgramParam.flashFilePath = programConfig.flashFilePath;
    12. aProgramParam.eepFilePath = programConfig.eepFilePath;
    13. aProgramParam.bUpdateEEP = programConfig.bUpdateEEP;
    14. aProgramParam.bUpdateFlash = programConfig.bUpdateFlash;
    15. aProgramParam.bUpdateFactorySetting = programConfig.bUpdateFactory;
    16. aProgramParam.factorySettingPath = programConfig.factoryFilePath;
    17. aProgramParam.bUpdateSN = programConfig.bUpdateSN;
    18. aProgramParam.firstSN = programConfig.sn;
    19. aProgramParam.bNeedSyncTime = programConfig.bNeedTimeSync;
    20. aProgramParam.bNeedResorteSetting = programConfig.bNeedRestoreCustomerSetting;
    21. console.log("before appendParam addressList");
    22. aConnectionBridge.appendParam(aProgramParam);
    To copy to clipboard, switch view to plain text mode 

    The problem is: when aConnectionBridge.appendParam(aProgramParam); called, QML create a new ProgramParam object, and pass the new ProgramParam object to ProgramParam's copy construct function. Thus, I get a empty ProgramParam list in m_programParamList.
    Log when button clicked as bellow:
    Qt Code:
    1. create a new ProgramParam ---------------------> creat a new object in QML
    2. set address! size is 2 ---------------------> assigne data, here address list size is 2
    3. qml: update addressList
    4. qml: before appendParam addressList ----------------------> before call aConnectionBridge.appendParam(aProgramParam);
    5. create a new ProgramParam ----------------------> QML create a new object
    6. copy construct len is 0 ----------------------> pass a empyt object to copy construct fucntion????? why?:confused:
    7. ConnectionBridge::appendParam p.size : 0 --------------------> call ConnectionBridge::appendParam, pass a empy ProgramParam object
    8. ProgramParamList::append p.size : 0 ----------------------> append "empty" ProgramParam object to list
    9. copy construct len is 0
    10. qml: after appendParam addressList
    11. qml: addrList: [1,4] -----------------------> infact, the address list should be [1,4], but QML pass [] to c++
    To copy to clipboard, switch view to plain text mode 


    Can any one tell me why?
    Attached Files Attached Files

Similar Threads

  1. Replies: 2
    Last Post: 2nd December 2013, 04:43
  2. Replies: 4
    Last Post: 2nd August 2012, 07:42
  3. Function call with QFile as parameter?
    By Pyry in forum Newbie
    Replies: 2
    Last Post: 26th May 2011, 00:10
  4. skip function parameter
    By mattia in forum General Programming
    Replies: 4
    Last Post: 22nd November 2007, 15:55
  5. const function parameter problems
    By stevey in forum General Programming
    Replies: 3
    Last Post: 18th December 2006, 22:22

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.