Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

call a function in another function



  • Hello guys , i created a new class and i created 2 functions ( moveLine and moveH) now i want to call moveLine in moveH , can someone help me ?thanks

    0_1551689739938_Capture d’écran 2019-03-04 à 09.50.53.png

    0_1551689754667_Capture d’écran 2019-03-04 à 09.50.46.png


  • Lifetime Qt Champion

    Hi
    move test and testa to class definition.
    then you can use it for the call
    moveLine(test);
    moveLine(testa);

    to be clear

    in tabWidget .h

    class tabWidget : xxxxxx {
    ...
    QTextEdit *test;
    QTextEdit *testa;
    }

    and then in .cpp
    you new them
    testa=new QTextEdit(this);
    ...

    and PLEASE post real code and not images. its annoying to use for answering.



  • @mrjj Thank you dude , i will post the code next time



  • @mrjj my question was i want to call the function

         moveLine(QLineEdit *test) 
    

    in another function her in

        moveH() //whithout argument
    

    when i call moveH() in my main program he will call

           moveLine(QLineEdit *test)

  • Lifetime Qt Champion

    @Zunneh
    Hi
    Why do you want to give it a QLineEdit when you call it from
    main program ?
    It seems a bit messy.
    Also what is the lineEdit ? You have some in tabWidget so i guess
    a good question is what you plan to do with them?



  • @mrjj
    i created a QLineEdit in main program to move it with moveLine , now i want to add some conditions in moveH to call

             MoveLine(QLineEdit *test ) 
    

    my objective is to minimise the code , i created the method moveLine(QLineEdit *test) and i want to call it in another methods ,
    so my question is , how to call a method in another method in the same class ?


  • Lifetime Qt Champion

    @Zunneh
    hi

    so function1 get a lineEdit
    and later when you call function2, it must know the line
    you got in function1?

    If you need to remember the QLineEdit, you must store it in the class.

    • how to call a method in another method in the same class ?
      you just call it. nothing extra. simply call it.

Log in to reply