Results 1 to 8 of 8

Thread: how do can I use my C++ code in qt and can it be translated into QT code

  1. #1
    Join Date
    Sep 2012
    Posts
    4
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default how do can I use my C++ code in qt and can it be translated into QT code

    I have a bioinformatics program that i want a GUI added to it. I just discoverd QT and I'm told it uses C++ code but when I analyze QT code it looks a heck of alot different from C++. where can I go to find the QT equivalent of my code or where is the best place to learn?

    this is my code I'm trying to convert
    does anybody have any tips on how to or how can I make this happen?

    Qt Code:
    1. #include<iostream>
    2. #include<fstream>
    3. #include<cstdlib>
    4. #include <string>
    5. using namespace std;
    6. int input;
    7. int main()
    8. {
    9.  
    10. cout<<"please enter a file name"<<endl;
    11. char filename[50];
    12. ifstream seq;
    13. cin.getline(filename, 50);
    14. seq.open(filename);
    15.  
    16. if(!seq.is_open()){
    17. exit(EXIT_FAILURE);
    18. }
    19.  
    20. char DNA[50];
    21. char RNA[50];
    22. seq>>DNA;
    23.  
    24. cout<< DNA <<" "<<endl;
    25.  
    26. int len=0;
    27. for(int i=0; i<=sizeof(DNA); i++){
    28.  
    29. if (DNA[i] == 'A')
    30. {cout<<"U";
    31. RNA[i]='U';
    32. len++;
    33. }
    34. if (DNA[i] == 'G')
    35. {cout<<"C";
    36. RNA[i]='C';
    37. len++;
    38. }
    39. if (DNA[i] == 'C')
    40. {cout<<"G";
    41. RNA[i]='G';
    42. len++;
    43. }
    44.  
    45. if (DNA[i] == 'T')
    46. {cout<<"A";
    47. RNA[i]='A';
    48. len++;
    49. }
    50. }
    51. cout<<endl;
    52. for(int i=0; i<len; i++){
    53. cout<<RNA[i];
    54. }
    55. cout<<endl<<sizeof(DNA)<<endl;
    56. cout<<len<<endl;
    57. fstream file;
    58. file.open("RNA_DNASeq.txt",ios::out);
    59. file<<DNA<<endl<<RNA<<endl;
    60. file.close();
    61.  
    62. system("PAUSE");
    63. return 0;
    64. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: how do can I use my C++ code in qt and can it be translated into QT code

    Qt is a library not a language. Qt is written in C++ and designed to be used from C++ programs (although there are bindings for Python). All you require is a knowledge of C++ to learn how to use the Qt library. There are plenty of tutorials, examples and demos in the Qt documentation. That documentation is installed with the Qt library: run "assistant" or look at the Help in Qt Creator (if you have that).

    Your program is not designed for a GUI, whether it is Qt or any other kind, so you will need to think about how your GUI program should work.

    (I also suspect your program does not do what you expect)

  3. #3
    Join Date
    Sep 2012
    Posts
    4
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: how do can I use my C++ code in qt and can it be translated into QT code

    thanks for the reply
    Qt Code:
    1. (I also suspect your program does not do what you expect)
    To copy to clipboard, switch view to plain text mode 
    My program works perfectly

    Qt Code:
    1. Your program is not designed for a GUI, whether it is Qt or any other kind, so you will need to think about how your GUI program should work.
    To copy to clipboard, switch view to plain text mode 

    what I want it to do as far as it working with the GUI is I want the DNA sequence typed in a text field and then press a button and the RNA complement to print out in a second text field.

    How should my program be set up?

  4. #4
    Join Date
    Jan 2011
    Posts
    127
    Thanks
    42
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: how do can I use my C++ code in qt and can it be translated into QT code

    but when I analyze QT code it looks a heck of alot different from C++
    It is because Qt is not a standard of C++, Qt is one of the library of C++

    where can I go to find the QT equivalent of my code
    Hard to tell that which part of Qt you need to use.Who knows what kind of gui you want to design?

    where is the best place to learn?
    Go to the website of Qthttp://qt.nokia.com/learning
    Study the documents come with QtCreator, or find a book
    I would recommend "Foundation of Qt development" for you.

    Besides, about your codes, there are too many ways to get the same results,
    but I would show you one of the solution which almost base on the component of Qt

    Qt Code:
    1. /*
    2.  * you could use QMap to replace std::map, I use std::map because
    3.  * QMap do not support std::initializer_list in Qt4.8.2 yet.If QString
    4.  * is too expensive for your case, change it back to char
    5.  */
    6. inline std::map<QString, QString> const create_table()
    7. {
    8. return std::map<QString, QString>() = { {"A", "U"}, {"G", "C"}, {"C", "G"}, {"T", "A"} };
    9. }
    10.  
    11. inline void help2()
    12. {
    13. qDebug() << "please enter a file name";
    14. QString filename;
    15. QTextStream qtin(stdin);
    16. qtin >> filename;
    17. QFile file(filename);
    18. if(!file.open(QIODevice::WriteOnly) )
    19. {
    20. qFatal("can't open the file");
    21. }
    22.  
    23. QString dna;
    24. qDebug() << "please enter dna";
    25. qtin >> dna;
    26. qDebug() << dna;
    27.  
    28. auto table = create_table();
    29. QString rna;
    30.  
    31. int const dna_size = dna.size();
    32. for(int i = 0; i != dna_size; ++i)
    33. {
    34. qDebug() << table[QString(dna[i])];
    35. rna += table[QString(dna[i])];
    36. }
    37.  
    38. qDebug() << rna;
    39. qDebug() << endl<< dna_size <<endl;
    40.  
    41. QTextStream fileStream(&file);
    42. fileStream << dna << endl << rna << endl;
    43. }
    To copy to clipboard, switch view to plain text mode 

    source codes
    http://www.sendspace.com/file/qam63o

    Besides, try don't use system to pause the codes, you could try std::cin.get() instead.

    ps : I declare inline not because it should be but lazy to separate the declaration and implementation
    My codes are not a good example, please split the codes into different parts as your requirement.
    Last edited by stereoMatching; 6th September 2012 at 04:16.

  5. #5
    Join Date
    Sep 2012
    Posts
    4
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: how do can I use my C++ code in qt and can it be translated into QT code

    Thanks alot
    I see your way more advanced the me and I like your style of coding
    I will study this and thanks for the links
    I guess I have a long way to go if I'm gonna learn this but you gave my some real positive hope!!!!

    Thank you again

  6. #6
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: how do can I use my C++ code in qt and can it be translated into QT code

    With two QLineEdits (or a QLineEdit and a QLabel) and a QPushButton. You will need to put them into a parent QWidget with a layout. The QPushButton::clicked() signal can be used to trigger a slot that does your DNA->RNA translation on the text of the input widget and places the result into the result widget. You can use a QValidator to ensure only the character TAGC are accepted and upper case is forced. You use QString instead of your fixed C-style char arrays.

    Take a look at the Line Edits Example and the Address Book tutorial.


    Your current code assumes that DNA and RNA have been zeroed. This is not a safe assumption: the array contents are undefined. Here is what the array contents were immediately after declaring the arrays:
    Qt Code:
    1. DNA d8 20 60 00 00 00 00 00 24 23 60 00 00 00 00 00 a0 0e 40 00 00 00 00 00 44 a6 4b 06 c8 7f 00 00 00 00 00 00 00 00 00 00 f0 f7 20 51 ff 7f 00 00 c0 1d
    2. RNA 00 a3 01 07 c8 7f 00 00 00 00 00 00 00 00 00 00 f0 f7 20 51 ff 7f 00 00 c0 1d 60 00 00 00 00 00 01 00 00 00 00 00 00 00 c5 b0 04 07 c8 7f 00 00 a0 0e
    To copy to clipboard, switch view to plain text mode 
    Reading in from the file will put a zero terminator after the input data. However, since you do not limit yourself to the valid characters in the input string, or zero-terminate the RNA string after you build it you sometimes get rubbish characters in the output. Never mind, using either std::string or QString will make this problem go away.

  7. #7
    Join Date
    Sep 2012
    Posts
    4
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: how do can I use my C++ code in qt and can it be translated into QT code

    Thanks Chris & Stereo
    I'm going through the learn QT documentation and I'm really like WOW you can do alot with QT, more than I expected. the QT quick is awesome to it looks like you can design with QML and program with QT C++

    Thanks for the help you guys are really inspiring me right now!!!!

    Chris it looks like you turned the transcription portion of my code into the translation portion howd you do that???

  8. #8
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: how do can I use my C++ code in qt and can it be translated into QT code

    Chris it looks like you turned the transcription portion of my code into the translation portion howd you do that???
    By having an MSc is astronomy, not genetics, I free myself from the need to understand that transcription and translation have specific meaning in genetics. I meant translation in the computing sense of T translates (or maps) to A, G to C etc. I was not proposing determine the entire gene expression and protein folding result for a given DNA sequence

Similar Threads

  1. how to use C code in qt?
    By shakthi in forum Qt Programming
    Replies: 5
    Last Post: 24th July 2011, 17:46
  2. need help in qt code
    By doforumda in forum Qt Programming
    Replies: 5
    Last Post: 27th August 2010, 13:27
  3. GUI Code
    By waynew in forum Newbie
    Replies: 2
    Last Post: 12th October 2009, 12:12
  4. Pasting code from code tag in emacs
    By Gopala Krishna in forum General Discussion
    Replies: 0
    Last Post: 16th February 2007, 05:47
  5. Need help with C++ code!
    By therealjag in forum Qt Programming
    Replies: 4
    Last Post: 20th March 2006, 21:37

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.