Click here to Skip to main content
15,895,746 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: CTreeCtrl with CustomDraw Flickering Pin
SamwisePl7-May-17 19:47
SamwisePl7-May-17 19:47 
AnswerRe: CTreeCtrl with CustomDraw Flickering Pin
SamwisePl15-May-17 19:15
SamwisePl15-May-17 19:15 
GeneralRe: CTreeCtrl with CustomDraw Flickering Pin
leon de boer15-May-17 19:26
leon de boer15-May-17 19:26 
QuestionWinBioIdentify() function causing to stop service "WbioSrvc " when match found? Pin
Premnath Mali4-May-17 19:28
professionalPremnath Mali4-May-17 19:28 
Questionambiguity in multiple inheritance Pin
Member 1315992028-Apr-17 20:17
Member 1315992028-Apr-17 20:17 
AnswerRe: ambiguity in multiple inheritance Pin
Richard MacCutchan28-Apr-17 21:34
mveRichard MacCutchan28-Apr-17 21:34 
AnswerRe: ambiguity in multiple inheritance Pin
Jochen Arndt28-Apr-17 21:44
professionalJochen Arndt28-Apr-17 21:44 
QuestionEmbedding Python in C++ Pin
Member 1312483628-Apr-17 17:06
Member 1312483628-Apr-17 17:06 
I have tried using Selenium with both the PythonQt and the Python.h libraries. I have a Ubuntu 16.04 platform using QT Creator 4.2.2 with Qt5.8.0. I can get everything setup with either interpreter and call a simple Python class for strings from Qt. However when I try and use Selenium I end up having problems (running py script for Selenium from the prompt works fine). For instance, using python.h When PyObject_GetAttrString(pModule, "browser") is called I get a segmentation fault. I am assuming that I need to load the selenium module or set the python path to it in Qt, but I am not clear on how to do this with multiple modules/paths. This is my python code browser.py:

from selenium import webdriver
from selenium.webdriver.common.keys import Keys

class browser():
  def __init__(self):
    self.driver = None
    self.webelement = None
  def getbrowser(self, name):
    if name == "chrome":
      self.driver = webdriver.Chrome()
    elif name == "firefox":
      self.driver = webdriver.Firefox()    
  def getpage(self,page):
    self.driver.get(page)
  def getsearchelement(self,elementname):
    self.webelement = self.driver.find_element_by_name(elementname)
  def getsearch(self,search):
    self.webelement.send_keys(search + Keys.RETURN)
  def stopbrowser(self):
    self.driver.quit()
    
""" Following runs fine from prompt, crashes in PythonQt/python.h
browser = webdriver.Firefox()
browser.get('https:\\search.yahoo.com')
elem = browser.find_element_by_name('p')  # Find the search box
elem.send_keys('seleniumhq' + Keys.RETURN)
browser.quit()
"""


Here is the routine from my c++ code

MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow)
{

    ui->setupUi(this);

    // Doing it here for debugging
    PyObject *pName, *pModule, *pFuncSet, *pValue, *pClass, *pInst, *pArgs;
    PyObject *pGetBrowser, *pGetPage, *pGetSearchElement, *pGetSearch, *pStopBrowser;
    // Initialize the Python Interpreter
    Py_Initialize();
    PySys_SetPath("/home/user/CppCode/StocksWeb/src/");
    // Build the name object
    pName = PyString_FromString("browser");
    // Load the module object
    pModule = PyImport_ImportModule("browser");
    pClass = PyObject_GetAttrString(pModule, "browser");
    if(pClass != NULL && pModule != NULL ) {
        pArgs  = Py_BuildValue("(  )");
        pInst = PyEval_CallObject(pClass, pArgs);
        if ( pInst != NULL ) {
            pGetBrowser = PyObject_GetAttrString(pInst, "getbrowser");
            pGetPage = PyObject_GetAttrString(pInst, "getpage");
            pGetSearchElement = PyObject_GetAttrString(pInst, "getsearchelement");
            pGetSearch = PyObject_GetAttrString(pInst, "getsearch");
            pStopBrowser = PyObject_GetAttrString(pInst, "stopbrowser");
            if( PyCallable_Check(pGetBrowser) && PyCallable_Check(pGetPage) && PyCallable_Check(pGetSearchElement) && \
                    PyCallable_Check(pGetSearch) && PyCallable_Check(pStopBrowser) ) {
                pArgs  = Py_BuildValue("(s)","firefox");
                PyObject_CallObject(pGetBrowser, pArgs);
                pArgs  = Py_BuildValue("(s)","https:\\search.yahoo.com");
                PyObject_CallObject(pGetPage, pArgs);
                pArgs  = Py_BuildValue("(s)","p");
                PyObject_CallObject(pGetSearchElement, pArgs);
                pArgs  = Py_BuildValue("(s)","seleniumhq");
                PyObject_CallObject(pGetSearch, pArgs);
                PyObject_CallObject(pStopBrowser, NULL);
            }
        }
    }
    // Clean up
    Py_DECREF(pModule);
    Py_DECREF(pName);

    // Finish the Python Interpreter
    Py_Finalize();
}


Any help would be greatly appreciated!

modified 28-Apr-17 23:16pm.

QuestionVisual studio Pin
Member 1315949628-Apr-17 11:06
Member 1315949628-Apr-17 11:06 
AnswerRe: Visual studio Pin
jeron128-Apr-17 11:14
jeron128-Apr-17 11:14 
QuestionRe: Visual studio Pin
David Crow28-Apr-17 15:59
David Crow28-Apr-17 15:59 
Questionerror LNK2019: unresolved external symbol __stdio_common_vsprintf referenced in function sprint VS 2015 Pro Windows 10 Pin
ForNow28-Apr-17 9:00
ForNow28-Apr-17 9:00 
AnswerRe: error LNK2019: unresolved external symbol __stdio_common_vsprintf referenced in function sprint VS 2015 Pro Windows 10 Pin
Jochen Arndt28-Apr-17 22:12
professionalJochen Arndt28-Apr-17 22:12 
GeneralRe: error LNK2019: unresolved external symbol __stdio_common_vsprintf referenced in function sprint VS 2015 Pro Windows 10 Pin
ForNow29-Apr-17 16:49
ForNow29-Apr-17 16:49 
QuestionHelp Pin
Member 1302311827-Apr-17 5:29
Member 1302311827-Apr-17 5:29 
AnswerRe: Help Pin
Dave Kreskowiak27-Apr-17 6:04
mveDave Kreskowiak27-Apr-17 6:04 
AnswerRe: Help Pin
ThatsAlok11-May-17 20:47
ThatsAlok11-May-17 20:47 
QuestionHelp Pin
Member 1302311824-Apr-17 10:05
Member 1302311824-Apr-17 10:05 
AnswerRe: Help Pin
jeron124-Apr-17 10:38
jeron124-Apr-17 10:38 
GeneralRe: Help Pin
Member 1302311824-Apr-17 11:01
Member 1302311824-Apr-17 11:01 
GeneralRe: Help Pin
leon de boer25-Apr-17 5:16
leon de boer25-Apr-17 5:16 
AnswerRe: Help Pin
Richard MacCutchan24-Apr-17 21:58
mveRichard MacCutchan24-Apr-17 21:58 
QuestionRe: Help Pin
David Crow25-Apr-17 3:59
David Crow25-Apr-17 3:59 
QuestionUsing menu key Pin
_Flaviu23-Apr-17 21:34
_Flaviu23-Apr-17 21:34 
QuestionRe: Using menu key Pin
Richard MacCutchan23-Apr-17 21:56
mveRichard MacCutchan23-Apr-17 21:56 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.