QT Start External Program

Source: Internet
Author: User
Tags mkdir
Summary:
Usually, we run the shell program is in the terminal, and in the product, it is not possible to call the user to the terminal to hit the command bar; Also, when a system in a certain calculation function, I have done in another program, want to use the GUI program directly invoke it to run. So, in these cases, how do you run the shell script and the Linux program with the button on the GUI? The following is an example of how to invoke a shell program and run an application in a QT4 GUI program on mini6410.
With this example, you can test the functions of the Linux C library to invoke shell scripts and applications, or you can call the shell scripts and applications through QT functions. Blocking and non-blocking runs are also described.
Introduction:
Introduction: Based on mini6410 development platform, using QT4 to design a GUI interface HelloQt4, through the HelloQt4 interface button->clicked to start the SMPlayer player.
1, Design GUI graphical interface, create a button, and add code under clicked

The first method (50 lines) is to invoke the system (const char *string) in the Linux C function library;
The second method (51 lines) and the third method (53 54 lines) are functions in the QT;
When you need to explain, the above three methods are OK, but the first two methods block the process until the SMPlayer program ends, and the third method does not block the process and can run multiple tasks.
Also, we know that QT when running, to start Qws (qtwindows server), if the previous two methods, then SMPlayer run, to open a new qws, otherwise can not run, and in the third Way, you do not need to open the QWS, It shared a qws with HELLOQT4, so that the two programs could be seen in a single window.
2. New run script to start SMPlayer player
In the previous step, the QT program executed the/opt/run_smplayer script, but this script does not exist, we want to create it, open the/OPT directory of the Development Board, create a new Run_smplayer file, add the following


#!/Bin/sh

#测试用
#cd/opt/
#rm qt_create/
-RF
#sleep 3
#mkdir qt_create
#cd qt_create
#mkdir qt_create1
#cd qt_create1
#mkdir Qt_create2
#cd Qt_create2
#mkdir OK

#直接调用mplayer播放sdcard里的gq. avi file
#cd/usr/local/smplayer/bin
#. /Mplayer/sdcard/gq.avi

#启动友善的smplayer
Cd/usr/local/smplayer/bin
. /SMPlayer

3. Modify SMPlayer File
In a friendly root file system, the SMPlayer script in the/user/lical/smplayer/bin directory is problematic, and if you run it directly, there will be situations where the mouse and touchscreen are not available, and we will copy the SMPlayer script from the/bin directory. and remove the QWS from the last two lines. (As mentioned above, we want to multitask, we don't need to open another qws)
Export Home =/Root
Cd/usr/local/smplayer/
Exe__c. /SMPlayer #-QWS 1 >/dev/null
2 >/dev/null//Here is the screen word, true without underline
#hotplug

4, modify the RCS file, so that the boot on the run helloqt4i program
The RCS file is as follows:
# !
/bin/sh

PATH =/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin:
RunLevel = S
Prevlevel = N
Umask 022
Export PATH runlevel Prevlevel

#
# Trap Ctrl-c & C in
This shell so we can interrupt subprocesses.
#
Trap ":" INT QUIT TSTP
/Bin/hostname Crt

[-E/PROC/1] | |
/bin/mount-n-T proc None/proc
[-E/sys/class] | |
/bin/mount-n-T Sysfs None/sys
[-E/dev/tty] | |
/bin/mount-t Ramfs None/dev
/bin/mount-n-T Usbfs none/proc/bus/usb

Echo/sbin/mdev >
/Proc/sys/kernel/hotplug
/sbin/mdev-s
/Bin/hotplug
# mounting file system specified in
/Etc/fstab
Mkdir-p/dev/pts
Mkdir-p/DEV/SHM
/bin/mount-n-T devpts none/dev/pts-o mode = 0622
/bin/mount-n-T Tmpfs tmpfs/dev/shm
/bin/mount-n-T Ramfs none/tmp
/bin/mount-n-T Ramfs None/var
Mkdir-p/Var/empty
Mkdir-p/Var/log
Mkdir-p/Var/lock
Mkdir-p/Var/run
Mkdir-p/Var/tmp

/sbin/hwclock-s

Syslogd
/etc/rc.d/init.d/netd Start
echo "
"
>
/dev/tty1
echo "Starting networking ... "
>
/dev/tty1
Sleep 1
/etc/rc.d/init.d/httpd Start
echo "
"
>
/dev/tty1
echo "Starting Web server ... "
>
/dev/tty1
Sleep 1
/etc/rc.d/init.d/leds Start
echo "
"
>
/dev/tty1
echo "Starting LEDs service ... "
>
/dev/tty1
echo "
"
Sleep 1

echo "
"
>
/dev/tty1
/etc/rc.d/init.d/alsaconf Start
echo "Loading sound card config ... "
>
/dev/tty1
echo "
"
/Sbin/ifconfig lo 127.0. 0.1
/Etc/init.d/ifconfig-eth0

#/Bin/qt4 &
#echo "
"
>
/dev/tty1
#echo "Starting QT4 applications, please waiting ... "
>
/dev/tty1

#/Bin/smplayer &
#echo "
"
>
/dev/tty1
#echo "Starting SMPlayer applications, please waiting ... "
>
/dev/tty1

/Bin/hello_qt4app &
echo "
"
>
/dev/tty1
echo "Starting HELLO_QT4 applications, please waiting ... "
>
/dev/tty1


The Hello_qt4app script is as follows:
#!/Bin/sh

Rm/root/. config/
-RF;
Rm/root/. MPlayer/
-RF;

If [-e/etc/friendlyarm-ts-input.conf]; Then
. /etc/friendlyarm-ts-input.conf
Fi
True ${tslib_tsdevice: =/Dev/touchscreen}

Tslib_conffile =/etc/ts.conf

Export Tslib_tsdevice
Export Tslib_conffile

Export Tslib_plugindir =/usr/lib/ts
Export Tslib_calibfile =/etc/pointercal

Export Qws_display =: 1
Export Ld_library_path =/usr/local/lib: $LD _library_path
Export PATH =/Bin:/sbin:/Usr/bin/:/usr/sbin:/Usr/local/bin

If [-c/dev/touchscreen]; Then
Export Qws_mouse_proto = "Tslib:${tslib_tsdevice} mouseman:/dev/input/mice"
If [-e/etc/pointercal-a!
-s/etc/pointercal]; Then
Rm/etc/pointercal
Fi
Else
Export Qws_mouse_proto = "Mouseman:/dev/input/mice"
>/etc/pointercal
Fi

Export Qws_keyboard = TTY:/dev/tty1

Export Home =/Root

Cd/opt
. /HELLO_QT4-QWS 1 >/dev/null
2 >/Dev/null
HotPlug


Then, restart the Development Board, HELLO_QT4 program run, and then click the button, the player also bounced out.
Conclusion:
This routine is simple and practical, and describes the purpose of the function,

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.