ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Sorry for the undescriptive title. I'm having a bit of trouble at the moment.
I thought I'd make a small QT-based application, and completely forgot that I have very little experience in C++, which is proving to be a pain.
Now please excuse my rambling attempt to explain.
The application is (Yet another) sudo wrapper, but I kept it relatively simple so I wouldn't confuse myself.
The idea was, sometimes you use a launcher or something, and then realize you needed to sudo it. You could grab a terminal and poke it into that, but I don't like opening a new terminal unnecessarily, so I thought of this.
You launch this app, select from a combobox whether you want to use gksu or kdesudo (Depending on which WM/DE you're using), give it the command in a text box (E.g. 'gedit' 'kate' etc) and hit a button to run that. In theory, gksu or kdesudo would pop up and ask for the password, then the selected app would run as per normal as root.
I've got the interface done (that was the easy part) but having nothing to work from in the coding has proved to be the downfall here.
Basically, I have two functions (I think that's the word, anyway)
One for the quit button - I know you could just use the window manager's one, but I prefer to have one there anyway
The other's for the execute button, which reads the su wrapper to be used from the combobox, the command in the text box, pairs them together and runs them.
It sounds simple, and I've given it a go from the QTCreator help's snippets, and so far managed nothing that would build and run, unless I take out the code I tried to write. Which isn't very useful.
So now I ask if people can lend a hand to my coding block, and help get this working. Maybe not everyone will find it useful, but it's something I want to have around anyway.
Sorry for the undescriptive title. I'm having a bit of trouble at the moment.
I thought I'd make a small QT-based application, and completely forgot that I have very little experience in C++, which is proving to be a pain.
Now please excuse my rambling attempt to explain.
The application is (Yet another) sudo wrapper, but I kept it relatively simple so I wouldn't confuse myself.
The idea was, sometimes you use a launcher or something, and then realize you needed to sudo it. You could grab a terminal and poke it into that, but I don't like opening a new terminal unnecessarily, so I thought of this.
You launch this app, select from a combobox whether you want to use gksu or kdesudo (Depending on which WM/DE you're using), give it the command in a text box (E.g. 'gedit' 'kate' etc) and hit a button to run that. In theory, gksu or kdesudo would pop up and ask for the password, then the selected app would run as per normal as root.
I've got the interface done (that was the easy part) but having nothing to work from in the coding has proved to be the downfall here.
Basically, I have two functions (I think that's the word, anyway)
One for the quit button - I know you could just use the window manager's one, but I prefer to have one there anyway
The other's for the execute button, which reads the su wrapper to be used from the combobox, the command in the text box, pairs them together and runs them.
It sounds simple, and I've given it a go from the QTCreator help's snippets, and so far managed nothing that would build and run, unless I take out the code I tried to write. Which isn't very useful.
So now I ask if people can lend a hand to my coding block, and help get this working. Maybe not everyone will find it useful, but it's something I want to have around anyway.
Thanks.
I'm interested in this thread because I'm starting to read through documents on QT, but I can't help but wonder where your code is..
Quote:
It sounds simple, and I've given it a go from the QTCreator help's snippets, and so far managed nothing that would build and run, unless I take out the code I tried to write.
Why not just use an existing launcher and type "kdesu <command>" or "gksu <command>" in it?
This is meant to be for the one-off sort of thing where you don't actually run it often. Fair point though, but this is what I was trying to do.
As to the code, I didn't start writing the one for the command, just the quit. I figured it would be simpler and might provide the start of what I needed to figure out the other one.
What I had, based off what I gleaned from the QT help, was the following:
It wouldn't build, with the error 'Invalid use of qualified-name 'QCoreApplication::exit'
Which suggests to me that I'm either missing something, or I've made a mistake, showing just how little I know about C++ in general.
The second attempt used a snippet I got from a Google search, which is as follows:
Which in turn told me that a function (I'm guessing the int main part) wasn't allowed before a {
I took a guess and removed the int main line, resulting in a complaint about argc and argv not being declared. Another guess moved the 'int argc, char *argv[]' from the int main to the void MainWindow's brackets, which seemed to be the logical place for them.
That in turn gave me two errors I really don't know anything about, one 'prototype for 'void MainWindow:n_btnquit_clicked(int, char**)' does not match any in class 'MainWindow' and in the corresponding .h file 'candidate is: void MainWindow:nbtnquit_clicked()'
That's what I've tried so far. No doubt it shows off my lack of knowledge over this.
main is the "main" function, which all programs must contain. It is where your program begins execution.
argc and argv are special variables for commandline arguments.
argc is the number of arguments, and argv[] is an array of arguments entered on the command line at the time of execution.
Quitting or executing things after the execution of the program indicates that command line arguments have been handled a good while ago, and therefore are not relevant to quitting the program, or executing other commands within a running program.
I wonder, for example, if my initial guess on how to write a GUI button that will terminate the program is correct.
void QCoreApplication::exit ( int returnCode = 0 ) [static]
Tells the application to exit with a return code.
After this function has been called, the application leaves the main event loop and returns from the call to exec(). The exec() function returns returnCode. If the event loop is not running, this function does nothing.
By convention, a returnCode of 0 means success, and any non-zero value indicates an error.
Note that unlike the C library function of the same name, this function does return to the caller -- it is event processing that stops.
Also, to help you better understand parameters(arguments, values, etc)
Code:
#include <iostream>
//declares function declaredfunction()
int declaredfunction(int parameter1, char parameter2, double parameter3);
// this function takes 3 parameters, int, char, double, in that order.
int main()
{
// these variables are local to main, and are being passed BY VALUE
// to the function declaredfunction()
int a = 5;
char b = '5';
double c = 5.50;
// notice that there are no datatypes associated with the function call
std::cout << declaredfunction(a,b,c) << std::endl;
}
int declaredfunction(int parameter1, char parameter2, double parameter3)
{
// makes parameter 1 == 6
parameter1 += 1;
// makes parameter 3 == 5, maybe anyway..
parameter3 = (parameter2 - '0');
std::cout << parameter3 << std::endl;
// returns parameter 1 which is 6. This means that if
// in main you had int test = declaredfunction(), then test would be 6
return parameter1;
}
In Qt you would create a number of methods for each action (check out the documentation for QAction), these will be special methods called slots (again checkout the documentation for Slots and Signals) These slots will then be connected to the GUI widgets that you have selected. This allows the same action to be connected to a button, a menu item and a short-cut key.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.