首页 \ 问答 \ 包装类型为QWidget的c / c ++对象已被删除(wrapped c/c++ object of type QWidget has been deleted)

包装类型为QWidget的c / c ++对象已被删除(wrapped c/c++ object of type QWidget has been deleted)

class window25(QtWidgets.QMainWindow):
    def __init__(self):
        try:
            super(window25,self).__init__()
            self.lineedit=QtWidgets.QLineEdit()
            self.checkbox=QtWidgets.QCheckBox()
            self.optBox=QtWidgets.QRadioButton()
            self.btn=QtWidgets.QPushButton("press me")
            self.guichange()
            self.btn.clicked.connect(self.guichange)
            self.show()
        except Exception as E:
            print(E)
    def guichange(self):
        try:
            wid=QtWidgets.QWidget()
    #        self.setCentralWidget()
            myLayout=QtWidgets.QVBoxLayout()
            myLayout.addWidget(self.btn)
            myLayout.addWidget(random.choice([self.lineedit,self.checkbox,self.optBox]))
            wid.setLayout(myLayout)    
            self.setCentralWidget(wid)
        except Exception as E:
            print(E)


app=QtWidgets.QApplication([])
ex=window25()
sys.exit(app.exec_())

我试图做实验。虽然我知道QStackedWidget改变窗口,但我尝试了一些按下按钮的其他东西,随机更改mainWindow中央小部件。一些成功后(即按下按钮3,4次正确工作)“)但之后我得到了一个错误

包装类型QCheckBox的c / c ++对象已被删除

包装类型为QLineEdit的c / c ++对象已被删除

我无法理解哪条语句导致了这个错误,以及我为什么或者错在哪里


class window25(QtWidgets.QMainWindow):
    def __init__(self):
        try:
            super(window25,self).__init__()
            self.lineedit=QtWidgets.QLineEdit()
            self.checkbox=QtWidgets.QCheckBox()
            self.optBox=QtWidgets.QRadioButton()
            self.btn=QtWidgets.QPushButton("press me")
            self.guichange()
            self.btn.clicked.connect(self.guichange)
            self.show()
        except Exception as E:
            print(E)
    def guichange(self):
        try:
            wid=QtWidgets.QWidget()
    #        self.setCentralWidget()
            myLayout=QtWidgets.QVBoxLayout()
            myLayout.addWidget(self.btn)
            myLayout.addWidget(random.choice([self.lineedit,self.checkbox,self.optBox]))
            wid.setLayout(myLayout)    
            self.setCentralWidget(wid)
        except Exception as E:
            print(E)


app=QtWidgets.QApplication([])
ex=window25()
sys.exit(app.exec_())

I was trying to do the experiment.Although I know about QStackedWidget to change windows but I tried something else that is pressing a button randomly changes the mainWindow Central widget.After a couple of success(i.e. pressing button 3,4 times work correctly") but after that I got an error

wrapped c/c++ object of type QCheckBox has been deleted

wrapped c/c++ object of type QLineEdit has been deleted

i am unable to understand which statement caused this error and why or where I am wrong


原文:https://stackoverflow.com/questions/48125641
更新时间:2023-11-19 11:11

最满意答案

有一个在您使用的CSV模块的README中生成CSV的示例:

file = File.open!("test.csv", [:write, :utf8])
table_data |> CSV.encode |> Enum.each(&IO.write(file, &1))

请注意, IO.write/2将字节写入设备,而IO.inspect/3 根据给定选项使用IO设备检查第二个参数 。 此外, CSV.encode/1需要二维列表

也就是说,您可能应该坚持使用IO.write/2中提到的IO.write/2 ,并在count生成一个2d列表而不是Map

defp count(words) when is_list(words) do
  words
  |> Enum.reduce(%{}, &update_count/2)
  |> Enum.reduce([], fn {k, v}, acc -> [[k, v] | acc] end)
end

defp tocsv(map) do
  file = File.open!("test.csv", [:write, :utf8])

  map
  |> IO.inspect
  |> CSV.encode
  |> Enum.each(&IO.write(file, &1))
end

在这种简单的情况下,我只是使用裸Elixir生成一个文件,但(假设count返回一个映射,就像在你的原始代码中一样):

defp tocsv(map) do
  File.open("test.csv", [:write, :utf8], fn(file) ->
    Enum.each(map, &IO.write(file, Enum.join(Tuple.to_list(&1), ?,) <> "\n"))
  end)
end

或者更简单:

defp tocsv(map) do
  File.write!("test.csv", 
     map
     |> Enum.map(Enum.join(Tuple.to_list(&1), ?,))
     |> Enum.join("\n"))
end

There is an example of producing the CSV in the README of the CSV module you use:

file = File.open!("test.csv", [:write, :utf8])
table_data |> CSV.encode |> Enum.each(&IO.write(file, &1))

Please note, that IO.write/2 writes the bytes to the device, while IO.inspect/3 inspects the second argument according to the given options using the IO device. Also, CSV.encode/1 expects a two-dimensional list.

That said, you probably should stick with IO.write/2 as mentioned in the example, and produce a 2d list in count rather that a Map:

defp count(words) when is_list(words) do
  words
  |> Enum.reduce(%{}, &update_count/2)
  |> Enum.reduce([], fn {k, v}, acc -> [[k, v] | acc] end)
end

defp tocsv(map) do
  file = File.open!("test.csv", [:write, :utf8])

  map
  |> IO.inspect
  |> CSV.encode
  |> Enum.each(&IO.write(file, &1))
end

In such an simple case, I would just use bare Elixir to produce a file, though (assuming count returns a map, as in your original code):

defp tocsv(map) do
  File.open("test.csv", [:write, :utf8], fn(file) ->
    Enum.each(map, &IO.write(file, Enum.join(Tuple.to_list(&1), ?,) <> "\n"))
  end)
end

Or, even simpler:

defp tocsv(map) do
  File.write!("test.csv", 
     map
     |> Enum.map(Enum.join(Tuple.to_list(&1), ?,))
     |> Enum.join("\n"))
end

相关问答

更多
  • In [3]: s.to_csv('/home/wesm/tmp/sfoo.csv') In [4]: Series.from_csv('/home/wesm/tmp/sfoo.csv') Out[4]: a 1 b 2 您也可以将header=None, index_col=0, squeeze=True传递给read_csv类似于Rutger Kassies的建议。 In [3]: s.to_csv('/home/wesm/tmp/sfoo.csv') In [4]: Series. ...
  • 无需使用循环。 你可以使用data.table方法,这将更有效和更快。 library(data.table) # create a column with row positions setDT(dt)[, rowpos := .I] # save each line of your dataset into a separate .csv file dt[, write.csv(.SD, paste0("output_", rowpos,".csv")), by ...
  • 有一个在您使用的CSV模块的README中生成CSV的示例: file = File.open!("test.csv", [:write, :utf8]) table_data |> CSV.encode |> Enum.each(&IO.write(file, &1)) 请注意, IO.write/2将字节写入设备,而IO.inspect/3 根据给定选项使用IO设备检查第二个参数 。 此外, CSV.encode/1需要二维列表 。 也就是说,您可能应该坚持使用IO.write/2中提到的IO.wri ...
  • 以下是您的宏必须如何将数据写入2列: VERSION BUILD=10.4.28.1074 TAB T=1 SET !DATASOURCE prefectures.csv SET !DATASOURCE_COLUMNS 1 SET !TIMEOUT_STEP 1 SET !ERRORIGNORE YES SET !LOOP 1 SET !DATASOURCE_LINE {{!LOOP}} URL GOTO=https://www.google.fr/search?q={{!COL1}} TAG POS=1 ...
  • 所以我终于弄明白了。 似乎文档缺少关于Streaming API的一些关键细节。 基本上我是在正确的轨道上,我只需要在代码中更早地创建索引。 我最终使用了AbstractIndexCreationTask,我比PutIndex方法更喜欢,虽然我不确定他们是否做同样的事情。 在任何情况下,这都有效: var store = new EmbeddableDocumentStore { DataDirectory = "data" }; ...
  • 您实际上没有向CSV文件写任何内容。 首先,不清楚为什么要打开文件进行写入然后再进行阅读。 然后从(现在为空)文件中读取。 然后,您从HTML中读取,并显示您想要的内容。 当然,如果您想要在其中显示数据,您将需要在某处写入CSV文件! 此外,如果您想通过Text :: CSV使用它们,最好避免使用文件句柄的裸字。 也许你需要这样的东西: my $csv = Text::CSV->new(); $csv->column_names('field1', 'field2', 'field3'); open $fh ...
  • 你不断删除文件,因为每次调用toto它都会打开result.csv进行写入,因此只剩下一次写入。 您需要打开一次文件,并创建一次wirter。 您还需要为此重新定义一次函数: import re import csv import string def toto(message,writer): message = message.lower() p = re.compile('|'.join(map(re.escape, string.punctuation))) no_punc ...
  • printRecord()方法采用Iterable(每个doc )。 例如一份清单。 因此,在代码的内部循环中,我们将为该行创建一个列表,而不是打印。 具体来说,给定此设置: def FILE_HEADER = ['Bond','Discount','Row','Price'] def fileName = 'out.csv' 和这个数据聚合(作为例子): def BondCounsel = ['bc1','bc2'] def DiscountRate = ['0.1','0.2'] def ro ...
  • 我想你可以明确地写出标题。 这是基于我到目前为止对我们的评论的理解 headers = ["Company_Name","Website","Street_Address", "City", "State", "Zip", "Phone","Email1", "Email2", "Email3", "Email4", "Email5"] set_headers = true csvs.each do |csv| city = csv.split(/[\/]|.csv-updated|.csv/).la ...
  • 你可以用lambda做到这一点,它简单快捷。 在阅读csv时也无需添加参数“names = ['Keyword']”。 import pandas as pd import datetime import os os.chdir('D:/mypc/') starter_df = pd.read_csv('keyword_results.csv') #dictionary created by function test_dic = {"John": 12, "Jake": 45, "Sarah": 3 ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。