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!
Code:
//class counter (where the function is defined)
Counter
( QString name,
int start
= 0,
bool firstTime
= true,
QDate CreationTime
= QDate::currentDate()) :
ClickTimes(start),
name(name),
firstTime(firstTime),
lastDate
(QDate::currentDate()),
CreationTime(CreationTime)
{}
{
return lastDate.toString("dd/MM/yyyy"); //this one works perfectly
}
{
return CreationTime.toString("dd/MM/yyyy"); //this one don't
}
/*---------------------------------------------------------*/
//MainWindow.cpp
//here is where the adding (creating the counter happens)
void MainWindow::addItemToList()
{
QString text2
= ui
->inputBox_2
->text
();
//setting the model (some deleted code just to be on point)
//model properties (some deleted code just to be on point)
//adding to the model (some deleted code just to be on point)
//setting the counter
pCounters.push_back(Counter(text2,0,true));
ui->inputBox_2->clear();
}
/*---------------------------------------------------------*/
//this is where it get called
void MainWindow::SaveFile()
{
QFile Save
("streak Counter.txt");
Save.
open(QIODevice::WriteOnly|QIODevice
::Text);
for(auto i = pCounters.begin();i != pCounters.end();i++)
{
if(i->isVirigin())
{
out << i->getName() << ',' << "virigin" << ',' << i->getCreationDate() << endl; //getCreationDate() doesn't work!
}
else
{
int counterNumber = i->getNumber();
out << i
->getName
() <<
',' <<
QString::number(counterNumber
)<<
',' << i
->getDate
() <<
',' << i
->getCreationDate
() <<
"\n";
}
}
Save.close();
}
//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.
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.
Code:
{
qDebug() << Q_FUNC_INFO << CreationTime;
return CreationTime.toString("dd/MM/yyyy"); //this one don't
}
Or with the debugger.
Cheers,
_
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
Code:
pCounters.push_back(Counter(text2,0,true));
to
Code:
pCounters.
push_back(Counter
(text2,
0,
true,
QDate::currentDate()));
//i thought this maybe the problem as Qt doesn't like my defaults
but still the variable don't get anything even though i explicitly passed the date to it.
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,
_
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....
Re: Qt Function doesn't work And there is no error
Attaching the program would definitely be useful.
Cheers,
_
6 Attachment(s)
Re: Qt Function doesn't work And there is no error
the program files part 1
the program files part 2
Re: Qt Function doesn't work And there is no error
Your copy constructor doesn't copy CreationTime.
Cheers,
_
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 :(
Re: Qt Function doesn't work And there is no error
Hello,
from your code in addItemToList:
Code:
pCounters.
push_back(Counter
(text2,
0,
true,
QDate::currentDate()));
You create a Counter object and copy it into a vector, so it uses the copy CTOR. In function loadFile:
Code:
pCounters.push_back(Counter(Fields[0],0,true));
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
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 :D
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 :D )
thanks guys for your help, i appreciate it :D
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 :)
Re: Qt Function doesn't work And there is no error
Hello,
Quote:
where does the copy constructor is being used?
The copy CTOR is being used when the vector::push_back(x) method copies its argument x to the internal destination.
Quote:
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
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....
Re: Qt Function doesn't work And there is no error
Quote:
Originally Posted by
eyad
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 :D )
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,
_
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
Re: Qt Function doesn't work And there is no error
Wow, So Much info in just 3 lines :D
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 :)