Page 1 of 2 12 LastLast
Results 1 to 20 of 29

Thread: General lineEdit, converting problem

  1. #1
    Join Date
    May 2007
    Posts
    315
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default General lineEdit, converting problem

    Hi. I've got a problem. I've got a piece of code:
    Qt Code:
    1. if (ui.beaufortBox->isChecked() && ui.knotBox_2->isChecked())
    2. {
    3. QString current = ui.fromLineEdit->text();
    4. int converted = current.toInt();
    5.  
    6. if (converted == 0)
    7. {
    8. ui.whiteLabel->setText("0-1");
    9. }
    10. }
    To copy to clipboard, switch view to plain text mode 
    program's contents you already know from my previous posts, but this is a new thing in it. The problem is, that when I select beaufortBox and knotBox_2 and click next step, type 0 to fromLineEdit, and click convert(which is connected to function where this code is) whiteLabel's text isn't set to 0-1. Why? Regards
    edit:
    but the problem isn't about value, i added
    Qt Code:
    1. else
    2. {
    3. ui.whiteLabel->setText("other");
    4. }
    To copy to clipboard, switch view to plain text mode 
    and still without result.
    Last edited by Salazaar; 15th June 2007 at 22:36.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: General lineEdit, converting problem

    Is the slot called at all?

  3. #3
    Join Date
    May 2007
    Posts
    315
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: General lineEdit, converting problem

    yes, it is called when user clicks convert button:
    Qt Code:
    1. connect(ui.convertButton, SIGNAL(clicked()), this, SLOT(convert()));
    To copy to clipboard, switch view to plain text mode 
    The only thing which has changed since last thread, is this function:
    Qt Code:
    1. void Dialog::convert()
    2. {
    3. if (ui.beaufortBox->isChecked() && ui.knotBox_2->isChecked())
    4. {
    5. QString current = ui.fromLineEdit->text();
    6. int converted = current.toInt();
    7.  
    8. if (converted == 0)
    9. {
    10. ui.whiteLabel->setText("0-1");
    11. }
    12. else
    13. {
    14. ui.whiteLabel->setText("none");
    15. }
    16. }
    17.  
    18.  
    19.  
    20.  
    21.  
    22. }
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: General lineEdit, converting problem

    But are you sure it is called? Did you verify that?

  5. #5
    Join Date
    May 2007
    Posts
    315
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: General lineEdit, converting problem

    Verify by checking code... How can I make myself sure it is called?

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: General lineEdit, converting problem

    Quote Originally Posted by Salazaar View Post
    Verify by checking code...
    This is not enough.
    How can I make myself sure it is called?
    use qDebug() or QMessageBox.

  7. #7
    Join Date
    May 2007
    Posts
    315
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: General lineEdit, converting problem

    And when I add qDebug code to my file, what is the next step to verify if it is called? And i should place qDebug at the beginning of function, right?

  8. #8
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: General lineEdit, converting problem

    do you know what qDebug() does or what it is for?
    From your questions it looks like you don't.
    You should get used to reading the docs about fucntions and class you don't know.
    Here is a link about deugging technics, be sure to read that.
    debug
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  9. #9
    Join Date
    May 2007
    Posts
    315
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: General lineEdit, converting problem

    I read it. So I should add this line:
    Qt Code:
    1. qDebug()<<"Dialog::convert()";
    To copy to clipboard, switch view to plain text mode 
    and see if compiler wrote QT_NO_DEBUG_OUTPUT right?

  10. #10
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: General lineEdit, converting problem

    No. Read that fine docs again. Do you know what a compiler is and when does it work and when does it not work? Compiler is for building the application and we want to test wheter the slot is called.

  11. #11
    Join Date
    May 2007
    Posts
    315
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: General lineEdit, converting problem

    I read docs again, but I don't understand

  12. #12
    Join Date
    May 2007
    Posts
    315
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: General lineEdit, converting problem

    Oh, now I understand. I have to run application in console too, and if I click a button which is connected to a function and qDebug line is in this function in console appears ClassName::Function(). I checked if Dialog::convert() is called. Yes, it is called. So why my function does nothing? If you don't remember the problem, look at my #1 post

  13. #13
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: General lineEdit, converting problem

    Quote Originally Posted by Salazaar View Post
    I checked if Dialog::convert() is called. Yes, it is called. So why my function does nothing?
    What happens when you put that line with qDebug() inside the block that follows the first if statement (i.e. line #5 in the code from post #3)?

  14. #14
    Join Date
    May 2007
    Posts
    315
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: General lineEdit, converting problem

    if I put qDebug() line
    Qt Code:
    1. qDebug()<<"Dialog::convert()";
    To copy to clipboard, switch view to plain text mode 
    in if clause instead of at the beginning of the function, I don't reach Dialog::convert() code in console

  15. #15
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: General lineEdit, converting problem

    Does the line edit contain only the "0" character? Could you post a screenshot of the line edit with the contents of the widget selected?

  16. #16
    Join Date
    May 2007
    Posts
    315
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: General lineEdit, converting problem

    Yes, it contains only 0 character. But even if not, it should set whiteLabel to "none" text. Here's the screenshot:
    http://allyoucanupload.webshots.com/...41797424490087

  17. #17
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: General lineEdit, converting problem

    Quote Originally Posted by Salazaar View Post
    if I put qDebug() line [...] in if clause instead of at the beginning of the function, I don't reach Dialog::convert() code in console
    What does that mean?

  18. #18
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: General lineEdit, converting problem

    Quote Originally Posted by Salazaar View Post
    Yes, it contains only 0 character. But even if not, it should set whiteLabel to "none" text. Here's the screenshot:
    http://allyoucanupload.webshots.com/...41797424490087
    We already asked you several times not to post images as links to external sites. Please use attachments for this purpose.

  19. #19
    Join Date
    May 2007
    Posts
    315
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: General lineEdit, converting problem

    Quote Originally Posted by jacek View Post
    We already asked you several times not to post images as links to external sites. Please use attachments for this purpose.
    Does it make difference for you?

    It means that this clause does not return true. Right? But why?

  20. #20
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: General lineEdit, converting problem

    Quote Originally Posted by Salazaar View Post
    Does it make difference for you?
    Yes, it does. The purpose of this site is not only to help people with their problems by answering questions, but also to capture knowledge, so other people can solve their problems just by searching the forum and reading past threads. If you post part of the content on the external site, it simply might get lost.

    Quote Originally Posted by Salazaar View Post
    It means that this clause does not return true. Right?
    Right. Now use qDebug() to see what do the both isChecked() calls return.

Similar Threads

  1. Problem in converting QString to QChar array?
    By KaKa in forum Qt Programming
    Replies: 2
    Last Post: 19th March 2007, 01:38
  2. problem converting string-char-int
    By mickey in forum General Programming
    Replies: 1
    Last Post: 10th December 2006, 00:43
  3. Problem converting .ui files from Qt3 to 4
    By Amanda in forum Qt Programming
    Replies: 6
    Last Post: 28th October 2006, 05:34
  4. general sqlplugin problem
    By a550ee in forum Installation and Deployment
    Replies: 5
    Last Post: 28th February 2006, 11:03
  5. Replies: 10
    Last Post: 1st February 2006, 11:08

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.