Im Learning - please take a look
-
I all i decided to leave this :http://developer.qt.nokia.com/forums/viewthread/4011/
and start again from scratch.I also understand that what i am about to explain is probably not the correct way of doing things, but it will help me with what i need to do next (other labels etc), i really need to use the dateEdit for the calendar picker but i believe it best to start with basic labels and lines first.
Once again with the 7part tutorial for the address book, i have opened up part 7 and renamed everything. I am amazed it still works and displays what i want.
I am now at the point where i want to add new Qlabels and QLineEdits etc, ( i believe this is what you call a class)
On the .h file i have added all the eventual class's i think i will need its now just a question of implementing them and learning how.Q: Do i call each class once or do i need to call a new QLabel to the QT_BEGIN_NAMESPACE for every new label i want to use and or display.
I have actually included a new label and Line edit to the existing addressbook (by looking at the existing code, and reusing and renaming where necessairy and it displays correctly when the pro is run. It does all the expected stuff like clear and submit or save and load as and when the corresponding button is pressed.
The only problem i have come across is that when i hit the submit button no matter what i have entered in the dateLine it returns to the same as the nameLine.
This is the original from the tutorial and i believe it to be the only place left i can modify to get it working@void AddressBook::submitContact()
{
QString name = nameLine->text();
QString address = addressText->toPlainText();if (name.isEmpty() || address.isEmpty()) { QMessageBox::information(this, tr("Empty Field"), tr("Please enter a name and address.")); return; } if (currentMode == AddingMode) { if (!contacts.contains(name)) { contacts.insert(name, address); QMessageBox::information(this, tr("Add Successful"), tr(""%1" has been added to your address book.").arg(name)); } else { QMessageBox::information(this, tr("Add Unsuccessful"), tr("Sorry, "%1" is already in your address book.").arg(name)); } } else if (currentMode == EditingMode) { if (oldName != name) { if (!contacts.contains(name)) { QMessageBox::information(this, tr("Edit Successful"), tr(""%1" has been edited in your address book.").arg(oldName)); contacts.remove(oldName); contacts.insert(name, address); } else { QMessageBox::information(this, tr("Edit Unsuccessful"), tr("Sorry, "%1" is already in your address book.").arg(name)); } } else if (oldAddress != address) { QMessageBox::information(this, tr("Edit Successful"), tr(""%1" has been edited in your address book.").arg(name)); contacts[name] = address; } } updateInterface(NavigationMode);
}
@ -
And this is how iv'e change it so far:
@void AddressBook::submitContact()
{
QString name = nameLine->text();
QString date = dateLine->text();
QString address = addressText->toPlainText();if (name.isEmpty() || date.isEmpty() || address.isEmpty()) { QMessageBox::information(this, tr("Empty Field"), tr("Please enter a name and address.")); return; } if (currentMode == AddingMode) { if (!contacts.contains(name)) { contacts.insert(name, date, address); QMessageBox::information(this, tr("Add Successful"), tr(""%1" has been added to your address book.").arg(name)); } else { QMessageBox::information(this, tr("Add Unsuccessful"), tr("Sorry, "%1" is already in your address book.").arg(name)); } } else if (currentMode == EditingMode) { if (oldName != name) { if (!contacts.contains(name)) { QMessageBox::information(this, tr("Edit Successful"), tr(""%1" has been edited in your address book.").arg(oldName)); contacts.remove(oldName); contacts.insert(name, date, address); } else { QMessageBox::information(this, tr("Edit Unsuccessful"), tr("Sorry, "%1" is already in your address book.").arg(name)); } } else if (oldAddress != address) { QMessageBox::information(this, tr("Edit Successful"), tr(""%1" has been edited in your address book.").arg(name)); contacts[name] = address; } } updateInterface(NavigationMode);
}
@From this i recieve 'iterator insert' messages and have no idea what that is yet.
-
Looking at the code again i noticed this
@ } else if (oldAddress != address) {
QMessageBox::information(this, tr("Edit Successful"),
tr(""%1" has been edited in your address book.").arg(name));
contacts[name] = address;
}@So i pasted copied and pasted and changed the file to this:
@void AddressBook::submitContact()
{
QString name = nameLine->text();
QString date = dateLine->text();
QString address = addressText->toPlainText();if (name.isEmpty() || date.isEmpty() || address.isEmpty()) { QMessageBox::information(this, tr("Empty Field"), tr("Please enter a name and address.")); return; } if (currentMode == AddingMode) { if (!contacts.contains(name)) { contacts.insert(name, date, address); QMessageBox::information(this, tr("Add Successful"), tr(""%1" has been added to your address book.").arg(name)); } else { QMessageBox::information(this, tr("Add Unsuccessful"), tr("Sorry, "%1" is already in your address book.").arg(name)); } } else if (currentMode == EditingMode) { if (oldName != name) { if (!contacts.contains(name)) { QMessageBox::information(this, tr("Edit Successful"), tr(""%1" has been edited in your address book.").arg(oldName)); contacts.remove(oldName); contacts.insert(name, date, address); } else { QMessageBox::information(this, tr("Edit Unsuccessful"), tr("Sorry, "%1" is already in your address book.").arg(name)); } } else if (oldDate != date) { QMessageBox::information(this, tr("Edit Successful"), tr(""%1" has been edited in your address book.").arg(name)); contacts[name] = date; } } else if (oldAddress != address) { QMessageBox::information(this, tr("Edit Successful"), tr(""%1" has been edited in your address book.").arg(name)); contacts[name] = address; } } updateInterface(NavigationMode);
}
@From this i recieved messages about a ) and a } was expected for destruction, i couldn't figure it out so i added the symbols at the points indicated and then got loads of nasty messages.
I guess if i can get the submit button to submit the date without changing it to the name, i could have it cracked for implementing labels and lines, and maybe other class's.
If you have the time, i hope i've included enough info and code for you to look at and possibly see and explain what i am doing wrong or have missed.
Q: how far can undo go cos im going to need lots of them.