Results 1 to 9 of 9

Thread: sending amount of variable into button func

  1. #1
    Join Date
    Aug 2014
    Posts
    28
    Thanks
    15
    Qt products
    Qt5
    Platforms
    Windows

    Default sending amount of variable into button func

    Hi,
    let say i have signal like this
    Qt Code:
    1. void MainWindow::on_Next_clicked()
    2. {
    3. if(xy<=Ewords){
    4. getData(sfile);
    5. xy++;
    6. }
    7. else{
    8. restartApp();
    9. }
    10.  
    11. }
    To copy to clipboard, switch view to plain text mode 

    and this

    Qt Code:
    1. void MainWindow::on_mean_clicked()
    2. {
    3.  
    4. msg.setText("over here");
    5. msg.exec();
    6. }
    To copy to clipboard, switch view to plain text mode 

    now i want to send amount of xy every time i click on next button (on_Next_clicked) without calling mean button(on_mean_clicked)
    i will be grateful for help.

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: sending amount of variable into button func

    Those two functions are slots not signals.

    You want to "send the amount of xy" where?

  3. The following user says thank you to ChrisW67 for this useful post:

    ramin.lich (23rd April 2015)

  4. #3
    Join Date
    Aug 2014
    Posts
    28
    Thanks
    15
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: sending amount of variable into button func

    thanks
    oh sorry for bad topic i forgot to put this
    i want to send xy to on_mean_clicked

  5. #4
    Join Date
    Oct 2009
    Posts
    483
    Thanked 97 Times in 94 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: sending amount of variable into button func

    Quote Originally Posted by ramin.lich View Post
    thanks
    oh sorry for bad topic i forgot to put this
    i want to send xy to on_mean_clicked
    That still does not make any sense. What do you mean by "sending" a variable to a method with no parameters? Do you want to use the value of xy in the body of on_mean_clicked, perhaps to display it in the message box?

  6. The following user says thank you to yeye_olive for this useful post:

    ramin.lich (23rd April 2015)

  7. #5
    Join Date
    Aug 2014
    Posts
    28
    Thanks
    15
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: sending amount of variable into button func

    yes i want use value of xy in body of on_mean_clicked but if i use it with simple parameter like this

    Qt Code:
    1. void MainWindow::on_Next_clicked()
    2. {
    3. if(xy<=Ewords){
    4. getData(sfile);
    5. xy++;
    6. on_mean_clicked(xy);
    7. }
    8. else{
    9. restartApp();
    10. }
    11.  
    12. }
    To copy to clipboard, switch view to plain text mode 

    it will run whole func its just like someone clicked on Mean button but im not. i only want to use this amount in on_mean_clicked func
    i hope i explained clear.
    sorry for my bad english its not my native language.

  8. #6
    Join Date
    Oct 2009
    Posts
    483
    Thanked 97 Times in 94 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: sending amount of variable into button func

    What should happen when the user clicks the "Mean" button? Should the text in the message box be "over here" as it is now or should it depend on the current value of xy? By the way, can you post your whole code? The declaration of xy is missing.

    You really need to express more clearly what you want to achieve.

  9. The following user says thank you to yeye_olive for this useful post:

    ramin.lich (23rd April 2015)

  10. #7
    Join Date
    Aug 2014
    Posts
    28
    Thanks
    15
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: sending amount of variable into button func

    i dont think whole code needed.
    first the xy will declare in top of source code(global variable) :
    Qt Code:
    1. #include <QIODevice>
    2. #include <QDebug>
    3. #include <QMessageBox>
    4. #include <QProcess>
    5.  
    6. int Ewords=-1,Fwords=-1;
    7. void ScanData();
    8. void restartApp();
    9. void signalGiver(int);
    10. int xy=0
    To copy to clipboard, switch view to plain text mode 
    now there will be some operation based on my program logic happen after that in on_next_clicked xy will give have value which this value is needed on on_mean_clicked(only value)
    when user push the mean button there will be some calculation with this value of xy i still doesnt write code of that calculation. those massagebox u see in my code are only a warning for me to know when i click on mean program process is over here.
    enough clearing?
    thanks

  11. #8
    Join Date
    Oct 2009
    Posts
    483
    Thanked 97 Times in 94 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: sending amount of variable into button func

    Since xy is a global variable, then it can be accessed from on_mean_clicked(), as in:
    Qt Code:
    1. void MainWindow::on_mean_clicked()
    2. {
    3. QMessageBox::information(this, "meh", QString("The current value of xy is %1.").arg(xy));
    4. }
    To copy to clipboard, switch view to plain text mode 
    I really do not understand what your problem is.

  12. #9
    Join Date
    Aug 2014
    Posts
    28
    Thanks
    15
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: sending amount of variable into button func

    oh :| my god.....
    i really was thinking when xy goes in on_next_clicked the value is only access able in on_next_clicked .

    never mind, and my question is because of low information of global variable(thats shame) now my problem solved.
    thanks

Similar Threads

  1. Use Push Button to change a variable
    By Qem1st in forum Newbie
    Replies: 4
    Last Post: 17th January 2013, 22:03
  2. sending quint32 variable in socket
    By sksingh73 in forum Newbie
    Replies: 1
    Last Post: 24th June 2010, 01:56
  3. Replies: 0
    Last Post: 28th June 2006, 20:49
  4. setTiles() func of QCanvas
    By Kapil in forum Newbie
    Replies: 1
    Last Post: 25th March 2006, 19:13
  5. where's the sleep() func?
    By TheKedge in forum Qt Programming
    Replies: 11
    Last Post: 2nd February 2006, 15:54

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.