Results 1 to 18 of 18

Thread: help: designing a simple dictionary in Qt

  1. #1
    Join Date
    Jul 2009
    Location
    Russia
    Posts
    12
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default help: designing a simple dictionary in Qt

    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.
    Attached Files Attached Files

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: help: designing a simple dictionary in Qt

    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?!?

  3. #3
    Join Date
    Jul 2009
    Location
    Russia
    Posts
    12
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: help: designing a simple dictionary in Qt

    yh trial version is fun.But is there any way u cud help me with the code?

  4. #4
    Join Date
    Jul 2009
    Location
    Russia
    Posts
    12
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: help: designing a simple dictionary in Qt

    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......

    Qt Code:
    1. #include <stdio.h>
    2. #include <string.hpp>
    3. #include <direct.h>
    4. #include <stdlib.h>
    5.  
    6. void main(){
    7. DIR *dirp;
    8. struct dirent *direntp;
    9. dirp = opendir( ".\\data" );
    10. direntp = readdir( dirp );
    11. int has=0; int sel=1; int sele=0; int stop=0;
    12. printf("Select dictionary:\n");
    13. while( true ) {
    14. if( direntp == NULL ) break;
    15. printf("%d - %s\n",sel,direntp->d_name);
    16. direntp = readdir( dirp );
    17. has=1;
    18. sel++;
    19. }
    20. if(has=1){printf("Enter your choice (1 - %d): ",sel-1);
    21. scanf("%d",&sele);}
    22. if(sele<1 || sele>=sel){printf("Invalid choice!"); exit(0);}
    23.  
    24. dirp = opendir( ".\\data" );\\opens whr file is
    25. direntp = readdir( dirp ); direntp = readdir( dirp );
    26. sel=0;
    27. while(sel<sele){direntp = readdir( dirp ); sel++; }
    28. printf("Active dictionary: %s\nPress CTRL+C to exit.",direntp->d_name);
    29. String file=direntp->d_name;
    30. char word[80];
    31.  
    32. while(true){
    33. printf("\nSearch for: ");
    34. scanf("%s",&word);
    35. FILE *fr;
    36. char buffer[80];
    37. fr = fopen( ".\\data\\"+file, "r" );
    38. if( fr != NULL ) {
    39. int cnt=0;
    40. for(int i=0; i<25;i++)
    41. fgets( buffer, 80, fr );
    42. while( fgets( buffer, 80, fr ) != NULL ){
    43. if(strstr(buffer,word)!=NULL){
    44. printf("%s",buffer);
    45. cnt++;
    46. if(cnt>2){printf(" Only first 2 matches listed.\n"); break;}
    47. }
    48. }
    49. fclose( fr );
    50. }
    51. else{
    52. printf("Cannot open dictionary file");
    53. exit(0);
    54. }
    55. }
    56. }
    57.  
    58. void main(){
    59. DIR *dirp;
    60. struct dirent *direntp;
    61. dirp = opendir( ".\\data" );
    62. direntp = readdir( dirp );
    63. direntp = readdir( dirp );
    64. direntp = readdir( dirp );
    65. int has=0; int sel=1; int sele=0; int stop=0;
    66. if( direntp == NULL ){printf("No dictionary was found in the 'data' directory. "); getchar(); exit(0);}
    67. printf("Select dictionary:\n");
    68. while( true ) {
    69. if( direntp == NULL ) break;
    70. printf("%d - %s\n",sel,direntp->d_name);
    71. direntp = readdir( dirp );
    72. has=1;
    73. sel++;
    74. }
    75. if(has=1){printf("Enter your choice (1 - %d): ",sel-1);
    76. scanf("%d",&sele);}
    77. if(sele<1 || sele>=sel){printf("Invalid choice!"); exit(0);}
    78.  
    79. dirp = opendir( ".\\data" );
    80. direntp = readdir( dirp ); direntp = readdir( dirp );
    81. sel=0;
    82. while(sel<sele){direntp = readdir( dirp ); sel++; }
    83. printf("Active dictionary: %s\nPress CTRL+C to exit.",direntp->d_name);
    84. String file=direntp->d_name;
    85. char word[80];
    86.  
    87. while(true){
    88. printf("\nSearch for: ");
    89. scanf("%s",&word);
    90. FILE *fr;
    91. char buffer[80];
    92. fr = fopen( ".\\data\\"+file, "r" );
    93. if( fr != NULL ) {
    94. int cnt=0;
    95. printf("___________________________________________________________\n");
    96. for(int i=0; i<25;i++)
    97. fgets( buffer, 80, fr );
    98. while( fgets( buffer, 80, fr ) != NULL ){
    99. if(strstr(buffer,word)!=NULL){
    100. printf("%s",buffer);
    101. cnt++;
    102. if(cnt>250){printf(" Only first 250 matches listed.\n"); break;}
    103. }
    104. }
    105. fclose( fr );
    106. printf("___________________________________________________________");
    107. }
    108. else{
    109. printf("Cannot open dictionary file");
    110. exit(0);
    111. }
    112. }
    113. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by wysota; 13th July 2009 at 13:43.

  5. #5
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: help: designing a simple dictionary in Qt

    Quote Originally Posted by king-gideon View Post
    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...

  6. #6
    Join Date
    May 2008
    Location
    Kyiv, Ukraine
    Posts
    418
    Thanks
    1
    Thanked 29 Times in 27 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: help: designing a simple dictionary in Qt

    What is the purpose of doing the following three times in a row?

    Qt Code:
    1. direntp = readdir( dirp );
    To copy to clipboard, switch view to plain text mode 
    I'm a rebel in the S.D.G.

  7. #7
    Join Date
    Jun 2008
    Posts
    14
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: help: designing a simple dictionary in Qt

    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()));

  8. #8
    Join Date
    Jul 2009
    Location
    Russia
    Posts
    12
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: help: designing a simple dictionary in Qt

    thanks so much wud take a look at it

  9. #9
    Join Date
    Jul 2009
    Location
    Russia
    Posts
    12
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: help: designing a simple dictionary in Qt

    i went thru the QT_TR_NOOP but i dnt rily understand how i cn form my database from it

  10. #10
    Join Date
    Jul 2009
    Location
    Russia
    Posts
    12
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: help: designing a simple dictionary in Qt

    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.

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

    Default Re: help: designing a simple dictionary in Qt

    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.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  12. #12
    Join Date
    Jul 2009
    Location
    Russia
    Posts
    12
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Unhappy i need help with dictionary

    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
    Attached Files Attached Files

  13. #13
    Join Date
    Dec 2007
    Posts
    628
    Thanks
    3
    Thanked 89 Times in 87 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: i need help with dictionary

    Quote Originally Posted by king-gideon View Post
    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.

  14. #14
    Join Date
    Jul 2009
    Location
    Russia
    Posts
    12
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: i need help with dictionary

    how do i go about the search in d memory?

  15. #15
    Join Date
    Dec 2007
    Posts
    628
    Thanks
    3
    Thanked 89 Times in 87 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: i need help with dictionary

    Open file.
    Read file contents in a string.
    Search the word in string.

  16. #16
    Join Date
    Jul 2009
    Location
    Russia
    Posts
    12
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: i need help with dictionary

    can u pls explain in detail how to do it?

  17. #17
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: i need help with dictionary

    maybe it would be better to use SQLite to keeping/searching/gettings/inserting words?
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  18. The following user says thank you to spirit for this useful post:

    king-gideon (17th July 2009)

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

    Default Re: i need help with dictionary

    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.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  20. The following user says thank you to wysota for this useful post:

    king-gideon (17th July 2009)

Similar Threads

  1. simple % curve diagram.
    By janEUcitzen in forum Qwt
    Replies: 3
    Last Post: 27th March 2009, 08:16
  2. A simple example of a tree model
    By YaK in forum Qt Programming
    Replies: 2
    Last Post: 4th March 2009, 17:15
  3. dictionary databases
    By rishiraj in forum Newbie
    Replies: 1
    Last Post: 5th January 2009, 08:30

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
  •  
Qt is a trademark of The Qt Company.