Results 1 to 5 of 5

Thread: slots questions that's probably really silly

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Sep 2017
    Posts
    12
    Thanks
    5
    Qt products
    Qt5
    Platforms
    Windows

    Default slots questions that's probably really silly

    I currently have another silly question, I have a layout in gui folder with two buttons that are exclusive and have a bool checked slot on them Also for the whole window I have a make template button with a clicked slot on it as well and here from my class.cpp file is the code:

    Qt Code:
    1. void Classy::on_Boy_clicked(bool checked)
    2. {
    3. QString Gender = "Boy";
    4. }
    5.  
    6. void Classy::on_Girl_clicked(bool checked)
    7. {
    8. QString Gender = "Girl";
    9. }
    10.  
    11. void Classy::on_MakeButton_clicked()
    12. {
    13.  
    14.  
    15. QString Gender;
    16.  
    17.  
    18. QFile writeFile( filename );
    19. if (!writeFile.open(QIODevice::Append | QIODevice::Text))
    20. {
    21. qDebug() << "Didn't open the file!";
    22. }
    23. else
    24. {
    25. QTextStream out (&writeFile);
    26. out << "Case Number: "+caseNumberText << endl;
    27. out << "Patient Name: "+ patientNameText << endl;
    28. out << "Gender: " + Gender<< endl;
    29.  
    30. }
    31.  
    32. }
    To copy to clipboard, switch view to plain text mode 

    I'm trying to figure out how to make the Gender variable viewable to multiple slots at the same time. All of the code I realize won't run I'm just using it as example, as I have written the other code for it to create a directory and create the file correctly. I found this article source: https://doc.qt.io/archives/qq/qq10-signalmapper.html but slightly confused as not all of the buttons in this instance are in the same layout.

    My humble thanks to any answers I get.

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,323
    Thanks
    316
    Thanked 871 Times in 858 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: slots questions that's probably really silly

    Umm, do you know C++? Have you heard of member variables in C++ classes? Like maybe adding a "QString gender;" member variable and using that instead of local stack variables in each slot?
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

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

    seerofsorrow (29th September 2017)

Similar Threads

  1. Silly Question/A very silly question
    By seerofsorrow in forum Newbie
    Replies: 1
    Last Post: 21st September 2017, 23:24
  2. Questions about signals/slots and QObject lifetimes
    By themolecule in forum Qt Programming
    Replies: 11
    Last Post: 24th May 2014, 18:45
  3. Replies: 2
    Last Post: 4th July 2010, 21:44
  4. Signals and Slots questions
    By Janek in forum Qt Programming
    Replies: 3
    Last Post: 29th December 2009, 21:47
  5. silly array element counter..
    By ct in forum General Programming
    Replies: 4
    Last Post: 3rd March 2006, 15:50

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.