PDA

View Full Version : help: designing a simple dictionary in Qt



king-gideon
13th July 2009, 11:14
i need to design a dictionary in Qt.i have already done the interface but am having problems with the code.
What i want to do is this
Its a three language dictionary(can make it two)
when i type in a word in a linedit box and press translate, it shud bring out the translated word in the other boxes.I intend to save all the words in a file so i cn work with the words saved in the file but i dnt know how to go about this.I wud also appreciate other idaes on how to go about it.

Lykurg
13th July 2009, 12:42
This is really no post for that section. Please also note the Newbie section.

i have already done the interface but am having problems with the code.
Sounds for me like: "I want to build a house. I already have the colour for the walls. I just don't know how to do the construction work..."
So maybe you just want to learn C++ first and have a look how Qt can help you with reading files etc. Your task is nothing special, simple design and therefore you don't need any suggestions, just knowledge of the programming language you use, and that you have to learn by yourself.

And really the "trial version" stuff in your sources is just a fun. Right?!?

king-gideon
13th July 2009, 12:49
yh trial version is fun.But is there any way u cud help me with the code?

king-gideon
13th July 2009, 13:01
actually i wrote something like this but its in console interface(that is like the dos screen)
but am having problems wen am to use the ui in qt......:(


#include <stdio.h>
#include <string.hpp>
#include <direct.h>
#include <stdlib.h>

void main(){
DIR *dirp;
struct dirent *direntp;
dirp = opendir( ".\\data" );
direntp = readdir( dirp );
int has=0; int sel=1; int sele=0; int stop=0;
printf("Select dictionary:\n");
while( true ) {
if( direntp == NULL ) break;
printf("%d - %s\n",sel,direntp->d_name);
direntp = readdir( dirp );
has=1;
sel++;
}
if(has=1){printf("Enter your choice (1 - %d): ",sel-1);
scanf("%d",&sele);}
if(sele<1 || sele>=sel){printf("Invalid choice!"); exit(0);}

dirp = opendir( ".\\data" );\\opens whr file is
direntp = readdir( dirp ); direntp = readdir( dirp );
sel=0;
while(sel<sele){direntp = readdir( dirp ); sel++; }
printf("Active dictionary: %s\nPress CTRL+C to exit.",direntp->d_name);
String file=direntp->d_name;
char word[80];

while(true){
printf("\nSearch for: ");
scanf("%s",&word);
FILE *fr;
char buffer[80];
fr = fopen( ".\\data\\"+file, "r" );
if( fr != NULL ) {
int cnt=0;
for(int i=0; i<25;i++)
fgets( buffer, 80, fr );
while( fgets( buffer, 80, fr ) != NULL ){
if(strstr(buffer,word)!=NULL){
printf("%s",buffer);
cnt++;
if(cnt>2){printf(" Only first 2 matches listed.\n"); break;}
}
}
fclose( fr );
}
else{
printf("Cannot open dictionary file");
exit(0);
}
}
}

void main(){
DIR *dirp;
struct dirent *direntp;
dirp = opendir( ".\\data" );
direntp = readdir( dirp );
direntp = readdir( dirp );
direntp = readdir( dirp );
int has=0; int sel=1; int sele=0; int stop=0;
if( direntp == NULL ){printf("No dictionary was found in the 'data' directory. "); getchar(); exit(0);}
printf("Select dictionary:\n");
while( true ) {
if( direntp == NULL ) break;
printf("%d - %s\n",sel,direntp->d_name);
direntp = readdir( dirp );
has=1;
sel++;
}
if(has=1){printf("Enter your choice (1 - %d): ",sel-1);
scanf("%d",&sele);}
if(sele<1 || sele>=sel){printf("Invalid choice!"); exit(0);}

dirp = opendir( ".\\data" );
direntp = readdir( dirp ); direntp = readdir( dirp );
sel=0;
while(sel<sele){direntp = readdir( dirp ); sel++; }
printf("Active dictionary: %s\nPress CTRL+C to exit.",direntp->d_name);
String file=direntp->d_name;
char word[80];

while(true){
printf("\nSearch for: ");
scanf("%s",&word);
FILE *fr;
char buffer[80];
fr = fopen( ".\\data\\"+file, "r" );
if( fr != NULL ) {
int cnt=0;
printf("__________________________________________________ _________\n");
for(int i=0; i<25;i++)
fgets( buffer, 80, fr );
while( fgets( buffer, 80, fr ) != NULL ){
if(strstr(buffer,word)!=NULL){
printf("%s",buffer);
cnt++;
if(cnt>250){printf(" Only first 250 matches listed.\n"); break;}
}
}
fclose( fr );
printf("__________________________________________________ _________");
}
else{
printf("Cannot open dictionary file");
exit(0);
}
}
}

Lykurg
13th July 2009, 13:03
u cud help me with the code?
No, because you have to learn C++ at fist and you have to look a little in the docs of Qt: QFile, QTextStream, QStringList, QCompleter, QDatabase...

lyuts
13th July 2009, 13:28
What is the purpose of doing the following three times in a row?



direntp = readdir( dirp );

manishkyl
13th July 2009, 18:32
what u want is not exactly i18n
but i guess you can have a look at i18n tutorial in qt

maybe you can just use the qt .qm files as your dictionary ..and no need of doing file operations
you can build your database by doing QT_TR_NOOP("KeywordinSourceLanuage")
and providing the translated texts in Qt linguist

then you can take the input of the first line edit
and set the looked up text

lineedit2->setText(tr(linedit1->text().ascii()));

king-gideon
14th July 2009, 07:00
thanks so much:) wud take a look at it

king-gideon
14th July 2009, 07:53
i went thru the QT_TR_NOOP but i dnt rily understand how i cn form my database from it:(

king-gideon
14th July 2009, 08:15
i still dnt understand how to integrate this into my code.I understood how to create a phrase bokk.... but after this point didnt understand further.:(

wysota
14th July 2009, 09:13
This is not a way to go for you.

What are your C++ skills? Can you transform the code you wrote into proper object oriented C++ code? I would start with that and use Qt classes for accessing files and directories. When you're done, come back here with the code and we'll see how to help you further.

king-gideon
17th July 2009, 13:54
i need to design a dictionary in Qt.Its a three language dictionary.when i type in a word in a linedit box and press translate, it shud bring out the translated word in the other boxes.I intend to save all the words in a file so i cn work with the words saved in the file

This is wat i have done
- i have written a code to create d file and a button(add words) to add more words to the file.Firstly i saved all files to the container QLinkedList and wen i close my program it transfers all the entries and saves them to the file.
My problem is this: i dnt know how to search for a string in the file i saved such that when i type a word in one QLineEdit and click on translate,it shows the other words in the saved file in the other two lineEdits.am kinda stocked here.i attached my codes and ui

yogeshgokul
17th July 2009, 13:57
My problem is this: i dnt know how to search for a string in the file

Qt doesn't provide anything like searching in file.
You have to load the files, in memory, then have to search in QString/QMap/Whatever.

king-gideon
17th July 2009, 13:59
how do i go about the search in d memory?

yogeshgokul
17th July 2009, 14:12
Open file.
Read file contents in a string.
Search the word in string.

king-gideon
17th July 2009, 14:38
can u pls explain in detail how to do it?

spirit
17th July 2009, 15:10
maybe it would be better to use SQLite to keeping/searching/gettings/inserting words?

wysota
17th July 2009, 23:00
I think it would be better if someone opened a search engine and read a bit about things he wants to do. And I mean algorithmics, not Qt. One has to think and have an idea how his program is to work, not shoot blindly. I don't see any ideas of the author here and we don't solve school projects here, that's one of the rules of this site. We're to help and guide, not do one's work for him/her.