Results 1 to 6 of 6

Thread: how to use "argc" and "argv" ?

  1. #1
    Join Date
    Jan 2006
    Posts
    185
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default how to use "argc" and "argv" ?

    I have a main.cpp class
    Qt Code:
    1. #include <QApplication>
    2. #include "server.h"
    3.  
    4. int main(int argc, char * argv[])
    5. {
    6. QApplication app(argc, argv);
    7. Server * server;
    8. server = new Server();
    9. return app.exec();
    10. }
    To copy to clipboard, switch view to plain text mode 

    At this point, I presume, the "app" instance has been inputed with the "argc" and "argv".

    How can I use this variables in my "server" instance ?

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: how to use "argc" and "argv" ?

    You can access them from any point in your application using QCoreApplication::arguments().

  3. #3
    Join Date
    May 2006
    Posts
    788
    Thanks
    49
    Thanked 48 Times in 46 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: how to use "argc" and "argv" ?

    And why Mac can not read argument on main?

    only linux & win open the file on list arguments

    Qt Code:
    1. int main(int argc, char *argv[]) {
    2.  
    3. QApplication a( argc, argv );
    4. QCoreApplication::setOrganizationName(_ORGANIZATION_NAME_);
    5. QCoreApplication::setOrganizationDomain(_PROGRAM_NAME_DOMAINE_);
    6. QCoreApplication::setApplicationName(_PROGRAM_NAME_);
    7. Gui_Main::self()->setWindowTitle( _PROGRAM_TITLE_ );
    8. Gui_Main::self()->show();
    9. Gui_Main::self()->Incomming(a.arguments());
    10. a.connect( &a, SIGNAL( lastWindowClosed() ), &a, SLOT( quit() ) );
    11. return a.exec();
    12. };
    13.  
    14. void Gui_Main::Incomming( QStringList files )
    15. {
    16.  
    17. if (files.size() > 0) {
    18. for (int i = 0; i < files.size(); ++i) {
    19. QString unfilone = files.at(i);
    20. qDebug() << "### unfilone " << unfilone;
    21. if (is_file(unfilone)) {
    22. if (unfilone.endsWith(".fo")) {
    23. OpenOtherResult(unfilone);
    24. } else if (unfilone.endsWith(".xml")) {
    25. LoadXmlFile(unfilone);
    26. } else if (unfilone.endsWith(".xsl")) {
    27. LoadXsltFile(unfilone);
    28. }
    29. }
    30. }
    31.  
    32. }
    33.  
    34. }
    To copy to clipboard, switch view to plain text mode 


    And dropEvent in event (url file ) is accepted from Mac Window....
    linux open if is not KDE also work on gnome or the fast xfce4 X


    Qt Code:
    1. void Gui_Main::Grabdata(const QMimeData *data)
    2. {
    3. if (!data) {
    4. return;
    5. }
    6. QList<QUrl> urlelist;
    7. if (data->hasUrls()) {
    8. urlelist = data->urls();
    9. for ( int i = 0; i < urlelist.size(); ++i ) {
    10. ////////QUrl oneurl = urlelist.at(i);
    11. QString unfilone = urlelist.at(i).toLocalFile();
    12. qDebug() << "### url " << unfilone;
    13. if (is_file(unfilone)) {
    14. if (unfilone.endsWith(".fo")) {
    15. OpenOtherResult(unfilone);
    16. } else if (unfilone.endsWith(".xml")) {
    17. LoadXmlFile(unfilone);
    18. } else if (unfilone.endsWith(".xsl")) {
    19. LoadXsltFile(unfilone);
    20. }
    21. }
    22. }
    23. }
    24. }
    To copy to clipboard, switch view to plain text mode 


    I like to fix this on mac .... is so easy drag url to task....

    the code can found on svn the last commit http://sourceforge.net/projects/visual-xsltproc/

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

    Default Re: how to use "argc" and "argv" ?

    How is this post related to the thread?

  5. #5
    Join Date
    May 2006
    Posts
    788
    Thanks
    49
    Thanked 48 Times in 46 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: how to use "argc" and "argv" ?

    Quote Originally Posted by wysota View Post
    How is this post related to the thread?
    main "argc" and "argv" && qstrinlist arguments() .... that not running! on mac...

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

    Default Re: how to use "argc" and "argv" ?

    Quote Originally Posted by patrik08 View Post
    main "argc" and "argv" && qstrinlist arguments() .... that not running! on mac...
    The thread is "how to use argc and argv", not "what do I do incorrectly so that argc and argv don't work for me". And what does a drop event have to do with argv?

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.