Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 171081
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T12:55:27+00:00 2026-05-11T12:55:27+00:00

Im writing a little python program that goes through an XML file and does

  • 0

Im writing a little python program that goes through an XML file and does some replacement of tags. It takes three arguments, a path from whcih it creates a directory tree, the XML file its reading and the xml file its outputting to. It works fine from the command line just passing in arguments. As its not just for me, i thought id put a Qt front on it. Below is the majority of the Qt front. MOVtoMXF is the class that does all the replacement. So you can see that im basically just grabbing strings and feeding them into the class that ive already made and tested.

class Form(QDialog):      def ConnectButtons(self):         self.connect(self.pathBrowseB, SIGNAL('clicked()'), self.pathFileBrowse)         self.connect(self.xmlFileBrowseB, SIGNAL('clicked()'), self.xmlFileBrowse)         self.connect(self.outputFileBrowseB, SIGNAL('clicked()'), self.outputFileBrowse)      def accept(self):         path = self.pathBox.displayText()         xmlFile = self.xmlFileBox.displayText()         outFileName = self.outfileNameBox.displayText()         print path + '  ' + xmlFile + ' ' + outFileName         mov1 = MOVtoMXF.MOVtoMXF(path, xmlFile, outFileName)         mov1.ScanFile()         self.done()      def pathFileBrowse(self):         file = str(QFileDialog.getExistingDirectory(self, 'Select Directory'))         self.pathBox.setText(file)      def xmlFileBrowse(self):         file = str(QFileDialog.getOpenFileName(self, 'Save File'))         self.xmlFileBox.setText(file)      def outputFileBrowse(self):         file = str(QFileDialog.getSaveFileName(self, 'Save File'))         self.outfileNameBox.setText(file) 

the probelm is that when i feed in a Path, it now comes back with an error, either the directory doesnt exist, or if I have a trailing slash on the end that

File ‘/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/posixpath.py’, line 62, in join elif path == ” or path.endswith(‘/’):

I think its probably some mismatch between the QFileDialog, the QString its passing back and the string the my python expects. but im not sure how to go about fixing it.

Im running on Max OS X 10.5.6 pyQt 4.4.4 QT 4.4.0

thanks for any help you can give.

Mark

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T12:55:27+00:00Added an answer on May 11, 2026 at 12:55 pm

    Two potential solutions.

    Method 1:

    If you must use the displayText() method, I suggest you wrap the call to displayText() with an explicit string cast:

    path = str(self.pathBox.displayText())  xmlFile = str(self.xmlFileBox.displayText())  outFileName = str(self.outfileNameBox.displayText()) 

    The reason is that displayText() returns what I believe is a constant memory reference at the C++ level, meaning that you are not being returned a copy of the QString, but actually whatever QString is available at the memory reference.

    When you call the displayText() function, it is the string you expected, but eventually it is something else when the contents at the memory reference are changed. I have noticed this peculiarity with several methods on different controls, most notably QDateEdit/QDateTimeEdit/QTimeEdit controls, where I typically have to make an explicit copy of, say, the QDate returned by the date() function of QDateEdit by wrapping it in a QDate constructor.

    Method 2:

    Otherwise, use the text() method instead. The QString returned is a constant value, instead of a constant memory reference. See this doc:

    http://doc.trolltech.com/4.4/qlineedit.html#text-prop

    displayText : const QString  text : QString 

    Update:

    It looks like Riverbank will be addressing this problem in future versions of PyQt in case anybody is still having this problem:

    PyQt4 Roadmap

    Implicit Copying of const&

    Implemented in current snapshots.

    When PyQt wraps a const& value returned by a C++ function it wraps the address of the value itself. Also, it does not enforce the const attribute. This can cause unexpected behavour (and program crashes) either by the underlying value disappearing or the value being unexpectedly modified.

    The correct way to handle this is to explicitly make a copy of the value using its type’s copy constructor. However, that is not Pythonic and knowing that it needs to be done requires knowledge of the C++ API.

    PyQt will be changed so that it will automatically invoke the copy constructor and will wrap the copy.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 218k
  • Answers 218k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Nope. You can't do that. The reason is that a… May 12, 2026 at 11:33 pm
  • Editorial Team
    Editorial Team added an answer I'm pretty certain that EF4 will use anything currently in… May 12, 2026 at 11:33 pm
  • Editorial Team
    Editorial Team added an answer Install Visual Studio 2008, smart device development is not yet… May 12, 2026 at 11:33 pm

Related Questions

I'm writing a little Python extension in C/C++, and I've got a function like
Im attempting to use a C++ extension for Python called PySndObj. and getting an
I'm making a script parser in python and I'm a little stuck. I am
I'm writing opengl code in python using the library pyglet. When I draw to

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.