Visit Our UNIX and Linux User Community

Python Script with C++Qt

Thread Tools Search this Thread
Top Forums Programming Python Script with C++Qt
# 1  
Old 09-30-2010
Python Script with C++Qt

i work under CentOS 5.5, Qt 4.7, Python 2.4.
i need to send data from C++ to Python.
i write a code but it's not work, i have an Inferior System error on it.
PyObject* objArg = Py_BuildValue("(z)", cKeyNum);
PyObject* objFunc = (PyObject*)Init;
pValue = PyEval_CallObject(objFunc, objArg);

if there any know how to solve this problem please answer me .

Last edited by HanyM.Magdy; 09-30-2010 at 03:24 PM..
# 2  
Old 09-30-2010
Please post the error.
# 3  
Old 09-30-2010
The inferior stopped because it received a signal from the Operating System.

Signal name :
Signal meaning :
Segmentation fault
# 4  
Old 09-30-2010
What is 'Init'? Where do you get it? Post all your code, if you can.
# 5  
Old 09-30-2010
 #ifndef QPYTHON_H
#define QPYTHON_H
#endif // QPYTHON_H
#include "python2.4/Python.h"
#include "QString"
#include "QFile"
#include "QTextStream"
#include "QSound"
#include "QMessageBox"
#include "phonon/AbstractAudioOutput"
#include "phonon/AbstractMediaStream"
#include "phonon/phonon"
class QPython
    QString strScript;
    static QString strANI;
    static QString strDNIS;
    QPython(QString _strScript)
    {strScript  = _strScript;}
    int PythonInitialize()
        return Py_IsInitialized();
    int process_expression(char* cScript, char* cKeyNum)
        PyObject *pValue;
        static PyMethodDef dvoice[] = {
            // "Python name", C Ffunction Code, Argument Flags, __doc__ description
            {"playwave", playwave, METH_VARARGS, ""},
            {"ClearDigitBuffer", ClearDigitBuffer, METH_NOARGS, ""},
            {NULL, NULL, 0, NULL}
        cKeyNum = "1";
        PyObject *objModule = PyImport_ImportModule("main");
        //PyObject *objArg = Py_BuildValue("(s)", cKeyNum);
        //PyObject *objFunc = PyObject_GetAttrString(objModule, "main");
        pValue = PyEval_CallObject(PyObject_GetAttrString(objModule, "main")
                                   , Py_BuildValue("(s)", cKeyNum));
        catch(QString strError)
        {QMessageBox msg;
        Py_InitModule("dvoice", dvoice);
        return PyRun_SimpleString(cScript);
    int process_expression_FILE(char *cFile, char* cKeyNum)
        static PyMethodDef dvoice[] = {
            // "Python name", C Ffunction Code, Argument Flags, __doc__ description
            {"Init", Init, METH_VARARGS, ""},
            {"playwave", playwave, METH_VARARGS, ""},
            {"ClearDigitBuffer", ClearDigitBuffer, METH_NOARGS, ""},
            {NULL, NULL, 0, NULL}
        PyObject* objArg = Py_BuildValue("(0)", cKeyNum);
        PyObject* objFunc = (PyObject*)Init;
        PyEval_CallObject(objFunc, objArg);
        Py_InitModule("dvoice", dvoice);
        FILE* file_1 = fopen(cFile, "r");
        return PyRun_SimpleFile(file_1, cFile);
    void PythonFinalize()
    //, QString strWaveFile, QBool bSkip, int iFuture
    static PyObject* playwave(PyObject* pSelf, PyObject* pArgs)
        char* strWaveFile;
        int *iSkip;
        int *iFuture;
        PyArg_ParseTuple(pArgs, "sii", &strWaveFile, &iSkip, &iFuture);
        QString ster(strWaveFile);
        Phonon::MediaObject *music = Phonon::createPlayer(Phonon::MusicCategory, Phonon::MediaSource(ster));
    static PyObject* ClearDigitBuffer(PyObject* pSelf, PyObject* pArgs)

the error causes in PyEval_CallObject() function
# 6  
Old 09-30-2010
And what about the code that calls this object?
# 7  
Old 09-30-2010
The PyEval_CallObject is in Python Classes i just call it.

Previous Thread | Next Thread
Test Your Knowledge in Computers #893
Difficulty: Easy
sed uses regular expressions, such as .* (zero or more of any character).
True or False?

9 More Discussions You Might Find Interesting

1. Programming

Create a C source and compile inside Python 1.4.0 to 3.7.0 in Python for ALL? platforms...

Hi all... As you know I like making code backwards compatible for as many platforms as possible. This Python script was in fact dedicated for the AMIGA A1200 using Pythons 1.4.0, 1.5.2, 1.6.0, 2.0.1, and 2.4.6 as that is all we have for varying levels of upgrades from a HDD and 4MB FastRam... (1 Reply)
Discussion started by: wisecracker
1 Replies

2. Windows & DOS: Issues & Discussions

How to execute python script on remote with python way..?

Hi all, I am trying to run below python code for connecting remote windows machine from unix to run an python file exist on that remote windows machine.. Below is the code I am trying: #!/usr/bin/env python import wmi c = wmi.WMI("xxxxx", user="xxxx", password="xxxxxxx")... (1 Reply)
Discussion started by: onenessboy
1 Replies

3. Shell Programming and Scripting

Capture run time of python script executed inside shell script

I have bash shell script which is internally calling python script.I would like to know how long python is taking to execute.I am not allowed to do changes in python script.Please note i need to know execution time of python script which is getting executed inside shell .I need to store execution... (2 Replies)
Discussion started by: Adfire
2 Replies

4. Shell Programming and Scripting

**python** unable to read the background color in python

I am working on requirement on spreadsheet in python scripting. I have a spreadsheet containing cell values and with background color. I am able to read the value value but unable to get the background color of that particular cell. Actually my requirement is to read the cell value along... (1 Reply)
Discussion started by: giridhar276
1 Replies

5. Shell Programming and Scripting

Python script called by a shell script

experts, i wrote a python script to do a certain job, i tried it and it is working fine, i want this script to be executed automatically after a ksh script, the problem is when i execute the ksh script my python script runes perfectly after the ksh script as I have include it at the end of the ksh... (1 Reply)
Discussion started by: q8devilish
1 Replies

6. Shell Programming and Scripting

Need a Python script

I work on various messages received from server and want to write a python script that can sort messages with unique flag values and give me the output in a text file. I get these messages in the form of .zcap file from server, in order to get messages from those files; I use an internal tool:... (0 Replies)
Discussion started by: Vijeta Laad
0 Replies

7. Shell Programming and Scripting

Passing variable from shell script to python script

I have a shell script which inturn call the python script, I want to pass two variables from shell script to python script for its execution. How do i achieve this ????? Eg: a=3 b=3; c= a+b exec python d=c+a Thanks in Anticipation (4 Replies)
Discussion started by: shashi792
4 Replies

8. Shell Programming and Scripting

Hi Python and shell script,the script hangs

Hi I need to run a shell script from a TCL script,the shell script in trun will run a python script 1.Tcl script set filename "./" python ./ $MYSB/test_scripts/delivery/ 3.I have my script. Here the problem i am facing is on running... (0 Replies)
Discussion started by: nathgopi214
0 Replies

9. Shell Programming and Scripting

How to run python script from a Tcl script

Hi I have a python script,i need to run this script from a tcl script.Can anyone let me know how to do this (1 Reply)
Discussion started by: nathgopi214
1 Replies

Featured Tech Videos