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

  • SEARCH
  • Home
  • 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 8492179
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T22:38:40+00:00 2026-06-10T22:38:40+00:00

I am making a user management system using PyQT4 + PostgreSQL 9.1. While writing

  • 0

I am making a user management system using PyQT4 + PostgreSQL 9.1. While writing the following code for establishing connection with the database, i get syntax error :-

from PyQt4 import QtSql, QtGui , QtCore
import _sha256
import psycopg2


def createConnection(): 

    QSqlDatabase db = QSqlDatabase.addDatabase("QPSQL"); 
    db.setDatabaseName("mysite");
    db.setUserName("postgres");
    db.setPassword("password");
    db.setHostName("localhost");
    bool ok = db.open();
    if not db.open():
        QtGui.QMessageBox.critical(None, QtGui.qApp.tr("Cannot open database"),
                QtGui.qApp.tr("Unable to establish a database connection.\n"
                              "This example needs PostgreSQL support."),
                QtGui.QMessageBox.Cancel)
        return False

    query = QtSql.QSqlQuery()
    query.exec_("create table usermanagement(ID int primary key,"
                "userid int,firstname varchar(20), lastname varchar(20),usertype varchar(15),password varchar(20),)")
    query.exec_("insert into usermanagement values(1, 'Danny','Boyle','normaluser','normaluser')")

    return True

The error message is as follows:-

QSqlDatabase db = QSqlDatabase.addDatabase(“QPSQL”);
^
SyntaxError: invalid syntax

  • 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. Editorial Team
    Editorial Team
    2026-06-10T22:38:41+00:00Added an answer on June 10, 2026 at 10:38 pm

    You can’t declare variable types in Python; a classname followed by a space followed by a variable name is not Python syntax.

    Just do db = QSqlDatabase.addDatabase("QPSQL").

    (You have the same problem at bool ok = ...)

    Your code also doesn’t define QSqlDatabase anywhere to begin with; presumably you mean to import it from somewhere.

    Also remove all of the semicolons from your code; they’re not required as statement terminators in Python and are considered bad style.

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

Sidebar

Related Questions

I'm making an Online Library Management System using ASP.NET (with C#). So far everything
I am going to be making a small user system but I have questions.
Hey, I'm making a simple user friendly css editor using Prototype. Anyway, I was
When I'm making user controls for both Winforms and ASP.NET, I find myself writing
I have a user login/reg system with a user management admin area. Just some
I am making a Gym management system in windows form ( .Net ) .
Am fairly new to PHP and am making a basic CRUD style management system.
I'm making a web based project management application using MySQL and PHP that uses
We're launching a new content management system and redoing our user input forms in
I am making a user status list of the following format A like B's

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.