Results 1 to 16 of 16

Thread: Qt Function doesn't work And there is no error

  1. #1
    Join Date
    Feb 2016
    Posts
    11
    Qt products
    Qt5
    Platforms
    Windows

    Default Qt Function doesn't work And there is no error

    The function ( QString getCreationDate() const ) doesn't return anything is it bugged or am i missing something obvious?

    although there is another function that almost do the same thing but for another variable and it works like charm...
    note* the compiler doesn't output any error. it just don't behave as expected!

    Qt Code:
    1. //class counter (where the function is defined)
    2. Counter( QString name,int start = 0,bool firstTime = true,QDate CreationTime = QDate::currentDate())
    3. :
    4. ClickTimes(start),
    5. name(name),
    6. firstTime(firstTime),
    7. lastDate(QDate::currentDate()),
    8. CreationTime(CreationTime)
    9. {}
    10.  
    11. QString getDate() const
    12. {
    13. return lastDate.toString("dd/MM/yyyy"); //this one works perfectly
    14. }
    15.  
    16. QString getCreationDate() const
    17. {
    18. return CreationTime.toString("dd/MM/yyyy"); //this one don't
    19. }
    20. /*---------------------------------------------------------*/
    21. //MainWindow.cpp
    22.  
    23. //here is where the adding (creating the counter happens)
    24. void MainWindow::addItemToList()
    25. {
    26. QString text2 = ui->inputBox_2->text();
    27.  
    28. //setting the model (some deleted code just to be on point)
    29.  
    30. //model properties (some deleted code just to be on point)
    31.  
    32. //adding to the model (some deleted code just to be on point)
    33.  
    34. //setting the counter
    35. pCounters.push_back(Counter(text2,0,true));
    36. ui->inputBox_2->clear();
    37. }
    38. /*---------------------------------------------------------*/
    39. //this is where it get called
    40.  
    41. void MainWindow::SaveFile()
    42. {
    43. QFile Save("streak Counter.txt");
    44. Save.open(QIODevice::WriteOnly|QIODevice::Text);
    45.  
    46. for(auto i = pCounters.begin();i != pCounters.end();i++)
    47. {
    48. QTextStream out(&Save);
    49. if(i->isVirigin())
    50. {
    51. out << i->getName() << ',' << "virigin" << ',' << i->getCreationDate() << endl; //getCreationDate() doesn't work!
    52.  
    53. }
    54. else
    55. {
    56. int counterNumber = i->getNumber();
    57. out << i->getName() << ',' << QString::number(counterNumber)<< ',' << i->getDate() << ',' << i->getCreationDate() <<"\n";
    58. }
    59. }
    60. Save.close();
    61. }
    To copy to clipboard, switch view to plain text mode 

    //output file (example)

    thing1,virigin,

    or

    thing2,3,22/2/2016,

    i hope that someone may pass by and help me... as no one did In StackOverflow.. and i really can't figure out whats the problem.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Qt Function doesn't work And there is no error

    Have you looked at the value of CreationTime inside that function?
    Is it a valid QDate object?

    E.g.
    Qt Code:
    1. QString getCreationDate() const
    2. {
    3. qDebug() << Q_FUNC_INFO << CreationTime;
    4. return CreationTime.toString("dd/MM/yyyy"); //this one don't
    5. }
    To copy to clipboard, switch view to plain text mode 
    Or with the debugger.

    Cheers,
    _

  3. #3
    Join Date
    Feb 2016
    Posts
    11
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Qt Function doesn't work And there is no error

    @anda_skoa

    well i never tried the qdebug before, however when i did what you said, CreationTime doesn't have anything in it ( "" ) .

    thats the QDebug message => class QString __cdecl Counter::getCreationDate(void) const QDate("")

    so i changed this

    Qt Code:
    1. pCounters.push_back(Counter(text2,0,true));
    To copy to clipboard, switch view to plain text mode 
    to

    Qt Code:
    1. pCounters.push_back(Counter(text2,0,true,QDate::currentDate())); //i thought this maybe the problem as Qt doesn't like my defaults
    To copy to clipboard, switch view to plain text mode 

    but still the variable don't get anything even though i explicitly passed the date to it.
    Last edited by eyad; 23rd February 2016 at 14:03. Reason: added the qdebug message

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Qt Function doesn't work And there is no error

    Since your member and your constructor argument have the same name, have you tried different names?

    Cheers,
    _

  5. #5
    Join Date
    Feb 2016
    Posts
    11
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Qt Function doesn't work And there is no error

    i tried this after reading you reply.
    but it didn't change a thing.....

    i may give you the whole solution if you want , its a small program after all (2 headers , 1 cpp , 1 ui) 56kb total
    thats how desperate iam....

  6. #6
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Qt Function doesn't work And there is no error

    Attaching the program would definitely be useful.

    Cheers,
    _

  7. #7
    Join Date
    Feb 2016
    Posts
    11
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Qt Function doesn't work And there is no error

    the program files part 1

    the program files part 2
    Attached Files Attached Files

  8. #8
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Qt Function doesn't work And there is no error

    Your copy constructor doesn't copy CreationTime.

    Cheers,
    _

  9. #9
    Join Date
    Feb 2016
    Posts
    11
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Qt Function doesn't work And there is no error

    yes sir, i know that cause i didn't use that constructor , not even once in the whole program, so it was going to be wasted time if i implemented it.

    did this interfere with that function or its still don't work cause it don't feel like it

  10. #10
    Join Date
    Oct 2009
    Location
    Germany
    Posts
    120
    Thanked 42 Times in 41 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Qt Function doesn't work And there is no error

    Hello,

    from your code in addItemToList:
    Qt Code:
    1. pCounters.push_back(Counter(text2,0,true,QDate::currentDate()));
    To copy to clipboard, switch view to plain text mode 
    You create a Counter object and copy it into a vector, so it uses the copy CTOR. In function loadFile:
    Qt Code:
    1. pCounters.push_back(Counter(Fields[0],0,true));
    To copy to clipboard, switch view to plain text mode 
    Again using the copy CTOR. Add some debug output into the copy CTOR and you will observe how often it is called.

    You should add CONFIG+=c++11 to your .pro file. Moreover, get your CTOR initializer lists into the correct order to avoid warnings. Your counter class does not need any special handling when being copied. So remove your copy CTOR and let the compiler do the magic. It will copy all elements.

    Best regards
    ars

  11. #11
    Join Date
    Feb 2016
    Posts
    11
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Qt Function doesn't work And there is no error

    oh, Thanks ars you did save the life of this Simple program.
    and yea , good tip i will do this.

    didn't imagine that the copy constructor is being used at all. well looks like i didn't go past the intermediate level afterall, but hey thats what they call "experience" , you gain it when you do your first hand craft

    and thanks too anda_soka i think he wanted to say that the problem is in the copy constructor but i didn't get it (please, be more clear when talking to a newbie )

    thanks guys for your help, i appreciate it
    have a good day

    oh, one quick question please (if you have time to answer this ofcourse)
    where does the copy constructor is being used? cause i don't have a debugger so i don't know how to find such info
    Last edited by eyad; 23rd February 2016 at 21:30.

  12. #12
    Join Date
    Oct 2009
    Location
    Germany
    Posts
    120
    Thanked 42 Times in 41 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Qt Function doesn't work And there is no error

    Hello,

    where does the copy constructor is being used?
    The copy CTOR is being used when the vector:ush_back(x) method copies its argument x to the internal destination.
    cause i don't have a debugger so i don't know how to find such info
    Which development environment do you use? If you use mingw based environment there is always a debugger available: gdb. If you really cannot get a debugger for your development environment I suggest to switch to a different one (e.g. mingw). As soon as your program gets more complex you will need your debugger for tracing crashes or following your program execution step by step in case it does not do what you expected.

    One more suggestion: Make your program compile without warnings. Compiling your current code throws warning messages which currently do not any harm to the software. But there will come the day when there is a severe warning that might crash your program execution and you don't see it because of tons of other warnings.

    Best regards
    ars

  13. #13
    Join Date
    Feb 2016
    Posts
    11
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Qt Function doesn't work And there is no error

    well, thanks for your reply.
    i just use Qt Creator 5.5 64bit community edition.

    at the point where you talk about mingw and the other "environments" well idk about this but i think the enviroment you are talking about are IDE-ish? if that is the case, nope i don't use any.

    although i tried to use vs 2013 + qt addin 1.2.4 which gave me terrible times trying to make it work, where every solution literally failed.
    so i use nothing, but qt creator itself which isn't that helpful (for obvious reasons....) -it even don't give me intelisense when i do something like i->(waiting for Counter.h functions) -

    well about the vs problem its a story for another day, however i will take this opportunity to post the link to this problem description which i made in StackOverflow and as usual nobody helped me

    maybe any of qt admins may see this and solve the problem....
    Last edited by eyad; 24th February 2016 at 02:30.

  14. #14
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Qt Function doesn't work And there is no error

    Quote Originally Posted by eyad View Post
    and thanks too anda_soka i think he wanted to say that the problem is in the copy constructor but i didn't get it (please, be more clear when talking to a newbie )
    Well, the problem was that the copy constructor did not copy the member you were trying to access and that is what I wrote
    The only other way I can come up with to write that is
    "Your copy constructor needs to copy CreationTime"

    Cheers,
    _

  15. #15
    Join Date
    Oct 2009
    Location
    Germany
    Posts
    120
    Thanked 42 Times in 41 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Qt Function doesn't work And there is no error

    @eyad:

    mingw is a port of Linux gcc to Windows (32, 64 bit). mingw itself does not come with any ide. However, a lot of Windows ides are integrating the mingw environment for compilation and debugging. Under Windows I'm using TDM MinGW 64 as compiler and Eclipse (and for some quick projects QtCreator) as ide. The same environment is used together with scripts for automating build processes. This is running on command line outside of any ide. So if you prefer working on command line mingw might be a good choice. Together with cygwin, msys or msys2 you can assemble a build environment under Windows where your scripts can easily be run under Linux too.

    Best regards
    ars

  16. #16
    Join Date
    Feb 2016
    Posts
    11
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Qt Function doesn't work And there is no error

    Wow, So Much info in just 3 lines
    well i didn't know a thing about this before reading your Reply.
    i will definitely research this, and ofcourse i appreciate your help so much guys

Similar Threads

  1. Replies: 10
    Last Post: 3rd February 2015, 21:24
  2. Replies: 15
    Last Post: 23rd December 2013, 07:38
  3. Replies: 3
    Last Post: 1st May 2013, 21:44
  4. why on Linux ,doesn't work?
    By maider in forum Qt Programming
    Replies: 5
    Last Post: 11th March 2010, 09:57
  5. qSort doesn't work with member function
    By ber_44 in forum Qt Programming
    Replies: 10
    Last Post: 2nd June 2007, 13:00

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