LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 07-13-2009, 10:23 PM   #1
MALDATA
Member
 
Registered: Mar 2005
Posts: 103

Rep: Reputation: 17
Passing command-line arguments to qglviewer application


I am learning how to use QGLviewer and I'm having a little trouble with a fairly simple concept. I want to give my program a file name as a command line argument. All of the sample programs I find have a main.cpp file like this:

Quote:
#include <QApplication>
#include "window.h"

int main(int argc, char *argv[])
{
QApplication app(argc, argv);
Window window;
window.show();
return app.exec();
}
Then the Window class, which is derived from QGLViewer, does all the program's actual work. If I want access to argc and argv, for example, to open and read a file that's passed as an argument, what would handle that? Is there a built-in way to get the arg variables to the window class, or do I need to just write a loadfile function and pass them? That seems a little clumsy to me, I feel like there's a better way, since this seems like a common task.

Any ideas?

Thanks!
 
Old 07-15-2009, 09:27 AM   #2
paulsm4
Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
Here's another (crude, but effective) way:
Code:
#include <QApplication>
#include "window.h"


// Declare these variables "extern" in the module that needs argc/argv
int g_argc;
char **g_argv;

int main(int argc, char *argv[])
{
  QApplication app(argc, argv);
  g_argc = argc;
  g_argv = argv;
  Window window;
  window.show();
  return app.exec();
}

Last edited by paulsm4; 07-15-2009 at 09:29 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Passing command line arguments through getopts and long options neville310 Programming 3 04-16-2007 06:38 AM
command line arguments containing ( Lotharster Linux - Newbie 3 01-05-2006 08:43 AM
Passing a text file to the command line as arguments wimnat Linux - General 2 12-05-2005 08:09 AM
passing a list of arguments to a command hdagelic Linux - General 2 05-09-2005 09:30 AM
Help with command line arguments ? synapse Linux - Newbie 2 02-23-2004 02:25 AM


All times are GMT -5. The time now is 02:03 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration