PDA

View Full Version : how to use "argc" and "argv" ?



probine
9th December 2006, 13:25
I have a main.cpp class


#include <QApplication>
#include "server.h"

int main(int argc, char * argv[])
{
QApplication app(argc, argv);
Server * server;
server = new Server();
return app.exec();
}


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 ?

jacek
9th December 2006, 13:35
You can access them from any point in your application using QCoreApplication::arguments().

patrik08
9th December 2006, 18:26
And why Mac can not read argument on main?

only linux & win open the file on list arguments



int main(int argc, char *argv[]) {

QApplication a( argc, argv );
QCoreApplication::setOrganizationName(_ORGANIZATIO N_NAME_);
QCoreApplication::setOrganizationDomain(_PROGRAM_N AME_DOMAINE_);
QCoreApplication::setApplicationName(_PROGRAM_NAME _);
Gui_Main::self()->setWindowTitle( _PROGRAM_TITLE_ );
Gui_Main::self()->show();
Gui_Main::self()->Incomming(a.arguments());
a.connect( &a, SIGNAL( lastWindowClosed() ), &a, SLOT( quit() ) );
return a.exec();
};

void Gui_Main::Incomming( QStringList files )
{

if (files.size() > 0) {
for (int i = 0; i < files.size(); ++i) {
QString unfilone = files.at(i);
qDebug() << "### unfilone " << unfilone;
if (is_file(unfilone)) {
if (unfilone.endsWith(".fo")) {
OpenOtherResult(unfilone);
} else if (unfilone.endsWith(".xml")) {
LoadXmlFile(unfilone);
} else if (unfilone.endsWith(".xsl")) {
LoadXsltFile(unfilone);
}
}
}

}

}




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





void Gui_Main::Grabdata(const QMimeData *data)
{
if (!data) {
return;
}
QList<QUrl> urlelist;
if (data->hasUrls()) {
urlelist = data->urls();
for ( int i = 0; i < urlelist.size(); ++i ) {
////////QUrl oneurl = urlelist.at(i);
QString unfilone = urlelist.at(i).toLocalFile();
qDebug() << "### url " << unfilone;
if (is_file(unfilone)) {
if (unfilone.endsWith(".fo")) {
OpenOtherResult(unfilone);
} else if (unfilone.endsWith(".xml")) {
LoadXmlFile(unfilone);
} else if (unfilone.endsWith(".xsl")) {
LoadXsltFile(unfilone);
}
}
}
}
}




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/

wysota
9th December 2006, 18:28
How is this post related to the thread?

patrik08
9th December 2006, 18:47
How is this post related to the thread?

main "argc" and "argv" && qstrinlist arguments() .... that not running! on mac...

wysota
9th December 2006, 19:03
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?